Ich möchte den Text des Befehls in der Titelleiste programmgesteuert ändern, aber es geschieht nicht. Warum ändert sich der Befehlsname "aaa" im folgenden Code nicht in "bbb"?Befehlstext programmgesteuert ändern
labourChargeSumCommand = new Command("") {
@Override
public void actionPerformed(ActionEvent evt) {
}
};
labourChargeSumCommand.setCommandName("aaa");
getToolbar().addCommandToRightBar(labourChargeSumCommand);
cb1.addActionListener(e -> {
if (cb1.isSelected()) {
labourChargeSumCommand.setCommandName("bbb");
getToolbar().revalidate();
}
});
Update: Alle meine Code
public class MyApplication {
private Form current;
private Resources theme;
Command labourChargeSumCommand;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
}
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
hi.add(new Label("Hi World"));
hi.show();
labourChargeSumCommand = new Command("") {
@Override
public void actionPerformed(ActionEvent evt) {
}
};
labourChargeSumCommand.setCommandName("aaa");
hi.getToolbar().addCommandToRightBar(labourChargeSumCommand);
Button bb = new Button("bb");
bb.addActionListener(e -> {
if (true) {
labourChargeSumCommand.setCommandName("bbb");
System.out.println(labourChargeSumCommand.getCommandName());
hi.getToolbar().revalidate();
hi.getToolbar().repaint();
}
});
hi.add(bb);
}
}
Hier habe ich einen BTN hinzugefügt und mit Code innerhalb seiner Aktion Hörer, das ist alles.
Erstes Debug ** cb1.isSelected() ** gibt ** true ** zurück –
yeahh, es gibt true zurück. Was ich tun möchte, ist, wenn ich das Kontrollkästchen anwähle, sollte der Befehl in der Titelleiste geändert werden. Es funktioniert für setTitle() aber nicht hier –
Versuchen Sie getToolbar() aufzurufen. Repaint(); nach getToolbar(). revalidate(); –