java - Is it possible to make JToggle text depend on its state? -


is possible me set text on jtoggle button "on" if selected , if not, "off"? i'm trying code:

    if(togbut.isselected()){         togbut.settext("on");     }      else if(!togbut.isselected()){            togbut.settext("off");     } 

but doesn't work. use netbeans 7.3.

your code correct.

it has put in change listener of toggle button.

    togglebutton.addchangelistener(new changelistener() {         @override         public void statechanged(changeevent event) {             if (togglebutton.isselected()){                 togglebutton.settext("on");             } else {                 togglebutton.settext("off");             }         }     }); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -