I have an app with 3 fxml files. The 1st is main window of app and most of work im doing here, but the 2 others fxml files allows me to change some settings and add more records to app. I made it that 2 small fxml files extends the main file. Basically:
public class FXMLDocumentController implements Initializable {
@FXML
private TextField txt;
@FXML
private Stage stage;
Symulacja symulacja = new Symulacja();
Promocja promocja = new Promocja();
@Override
public void initialize(URL url, ResourceBundle rb) {
txt.textProperty().bindBidirectional(promocja.getProgKwotyZetonow(), new NumberStringConverter());
labelProgKwotyZetonow.textProperty().bind(promocja.getProgKwotyZetonow().asString());
}
@FXML
public void zmienUstawienia() {
symulacja.zmienOkno("FXMLUstawienia.fxml", "Ustawienia");
}
@FXML
public void dodajKlientow() {
symulacja.zmienOkno("FXMLDodajKlienta.fxml", "Dodawanie");
}
}
It's main fxml Controller
public class FXMLUstawieniaController extends FXMLDocumentController{
@FXML
private TextField textProgKwota;
@FXML
private Button btnZatwierdzUstawienia;
@FXML
private TextField textProgIlosc;
@FXML
public void zatwierdzUstawienia() {
promocja.setProgIlosciZetonow(Integer.parseInt(textProgIlosc.getText()));
}
@Override
public void initialize(URL url, ResourceBundle rb) {
textProgKwota.textProperty().bindBidirectional(promocja.getProgKwotyZetonow(), new NumberStringConverter());
}
}
As you see I'm using properties to dynamically change what is showing in labelProgKwotyZetonow
and textProgKwota
.
When im not using the 2nd window txt
and labelProgKwotyZetonow
works fine, but when I'm initializing 2nd window I always get 0 in TextField and even if I change it this is not changing labelProgKwotyZetonow
.
It's strange to me because when I'm souting (System.out.println) the value of promocja.getProgKwotyZetonow()
in some places I get:
In function initialize
in the 2nd controller - 0.
In function zmienUstawienia
in 1st controller - the value from txt
/labelProgKwotyZetonow
.
In function zatwierdzUstawienia
in 2nd controller - the value from textProgKwota
.