B
B
bisswan2021-08-17 21:22:12
JavaFX
bisswan, 2021-08-17 21:22:12

Does the class change only when the application is opened again?

The class changes only when the application is opened again, how to make the class change when the state of the checkbox changes active / inactive

public void add(String name, String description, boolean value, Consumer<Boolean> onChanged) {
        FlowPane container = new FlowPane();
        CheckBox checkBox = new CheckBox();
        checkBox.setSelected(value);
        checkBox.setText(name);
        Text desc = new Text();
        desc.setText(description);
        container.getChildren().add(checkBox);
        container.getChildren().add(desc);

        checkBox.setOnAction((e) -> onChanged.accept(checkBox.isSelected()));
        componentList.getChildren().add(container);
        container.getStyleClass().add("optContainer");
        checkBox.getStyleClass().add("optCheckbox");
        desc.getStyleClass().add("optDescription");
        FlowPane.setMargin(desc, new Insets(0, 0, 0, 30));

        if(checkBox.isSelected()){
            desc.getStyleClass().add("optDescriptionactive");
        } else {
            desc.getStyleClass().add("optDescription");
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2021-08-17
@azerphoenix

I will assume that you need to add some kind of listener that will listen for changes in the state of the checkbox, and then add the appropriate class.
And now the following is happening: you change the state of the checkbox, but the check occurs earlier. The next time the application is launched, the condition is checked again, and since the checkbox is already selected, the class is added.
Take a look at this code:
https://www.tutorialspoint.com/javafx-example-to-s...
Pay particular attention to the Observable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question