Can someone tell me why there is a delay on Checkbox initialization with my Code?
What happens is that if I open the program, I have to click the Checkbox several times until it performes the desired Action.
The Controller also contains setter and getter methods.
Thanks a lot
public class Controller {
/* Defined variables */
@FXML
private CheckBox happyboxtick;
@FXML
private VBox topbox;
@FXML
private VBox designbox;
@FXML
public void initialize(){
happyboxtick.setSelected(true);
designbox.setVisible(false);
designbox.getChildren().removeAll();
topbox.setVisible(true);
topbox.getChildren().addAll();
}
@FXML
public void doSomething(ActionEvent e) {
//final CheckBox chk1 = new CheckBox("chk 1");
//final CheckBox chk2 = new CheckBox("chk 2");
EventHandler eh = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (event.getSource() instanceof CheckBox) {
CheckBox chk = (CheckBox) event.getSource();
//System.out.println("Action performed on checkbox " + chk.getText());
//System.out.println(chk);
if(chk.isSelected()){
System.out.println("My box is selected.");
topbox.setVisible(false);
topbox.getChildren().removeAll();
designbox.setVisible(true);
designbox.getChildren().addAll();
} else
{
System.out.println("My box is not selected.");
topbox.setVisible(true);
topbox.getChildren().addAll();
designbox.setVisible(false);
designbox.getChildren().removeAll();
}/*
if ("Yes".equals(chk.getText())) {
chk2.setSelected(!chk1.isSelected());
} else if ("chk 2".equals(chk.getText())) {
chk1.setSelected(!chk2.isSelected());
}*/
}
}
};
happyboxtick.setOnAction(eh);
//chk1.setOnAction(eh);
//chk2.setOnAction(eh);
}
}
The Code compiles perfectly. Initialization works. The right Option is selected. But when I click the box, I may have to click several times until the Elements are shown. And I don't know why.
Aucun commentaire:
Enregistrer un commentaire