lets say you have lable in MainWindow ..
and you want change value of this lable from Window2
Not in Same Window !!
i want the changes while the MainWindow its open
lets say you have lable in MainWindow ..
and you want change value of this lable from Window2
Not in Same Window !!
i want the changes while the MainWindow its open
It's easy if ur using 2 .fxml files with there own controllers if that's the case create a new class file namely 'AllControllers'
you have two 2 controllers namely ControllerWindow1 and ControllerWindow2
public class AllControllers {
private static ControllerWindow1 control1;
private static ControllerWindow2 control2;
public static ControllerWindow1 getControl1() {
return control1;
}
public static void setControl1(ControllerWindow1 control1) {
Controlls.control1 = control1;
}
public static ControllerWindow2 getControl2() {
return control2;
}
public static void setControl2(ControllerWindow2 control2) {
Controlls.control2 = control2;
}
}
You have to initialize each controller like this
public class ControllerWindow1 implements Initializable{
@FXML
public Label mylabel;
@Override
public void initialize(URL location, ResourceBundle resources) {
AllControllers.setControl1(this);
}
}
Now you can access your controller from any class. Just use
AllControllers.getControl1().mylabel.setText("hello");