1

I'd like to dynamically change the text of a Command depending on some state, so normally I went to Google and LWUIT blogs said that using refreshTheme() on MenuBar should do the trick. So I used the following code, but it sadly didn't work

if (isPlaying) {
          playButton.setCommandName("Pause");
}else{
          playButton.setCommandName("Play");
}
this.getMenuBar().refreshTheme();

Is there something wrong with my code? Or did I misunderstand something?

Mohamed Sobhy
  • 385
  • 1
  • 5
  • 17

1 Answers1

1

It won't refresh. The text of the button is set when the command is placed so you can't do that.

You will need to use removeCommand(cmd) followed by addCommand(newCmd).

Furthermore, refreshTheme() has absolutely nothing to do with anything.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • So I should just removeCommand then setCommandName and then addCommand again to the same form? Without the need to refreshTheme on form or menuBar or anything? – Mohamed Sobhy Oct 08 '13 at 10:39
  • Yes, that should work. A repaint might be necessary. Its been years, we are just busy with Codename One and I don't remember which issues were changed when. – Shai Almog Oct 09 '13 at 18:03