0

I have a very stupid question. I use a JToggleButton. now I want to know if the setSelected is true or false. thus an if function, but how to write one because I get errors.
thank for your support

if(Btn2.setSelected() = true){
    
    
}
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by superjj
1

The '=' is used for assignments. The '==' is used for comparison:

if(Btn2.getSelected() == true){
       
}

Or better if the Btn2.getSelected() returns boolean:

if ( Btn2.getSelected() ){
       
}

Edit: In your code you use Btn2.setSelected() . Perhaps you meant getSelected, because normally with set you pro-grammatically change the value

Edited by javaAddict: n/a

0
AbstractButton abstractButton = (AbstractButton) event.getSource();
boolean selected = abstractButton.getModel().isSelected();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.