Reputation: 670
I have a class which extends Button. There is a static boolean which is set to false. I want to change the text of all the buttons when this boolean changes value to true.
I tried playing with the bind feature but failed. :D
public class KolonaA extends Button{
...
static Boolean solved = false;
...
public KolonaA() {
super();
this.setPrefSize(size[0], size[1]);
this.setLayoutX(xCord + buttonCount * 30);
this.setLayoutY(yCord + buttonCount * 40);
//something like this:
this.textProperty().bind(solved ? "true" "false");
//CHANGE TEXT OF BUTTON WHEN solved CHANGES VALUE
...
}
...
}
Upvotes: 0
Views: 1201
Reputation: 36792
I am not completely sure if it is for just one button and a set of buttons. If you want to change the text of the custom button for which you have posted the code, instead of a Boolean, use a BooleanProperty
. Later you can add a Listener
to it and change the text of the Button accordingly.
public class KolonaA extends Button{
...
public BooleanProperty solved = new SimpleBooleanProperty();
...
public KolonaA() {
super();
solved.addListener((observable, oldValue, newValue) -> {
if(newValue)
setText("True");
else
setText("False");
});
...
}
...
}
Upvotes: 2