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){
    
    
}

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

AbstractButton abstractButton = (AbstractButton) event.getSource();
boolean selected = abstractButton.getModel().isSelected();