I am working on JavaFX application right now. All my gui is in .fxml format and through controller class manages all GUI components. However, I have difficulties with instantiating the controller class before I load FXML loader. I was unable to find a good solution for my question from others on stackoverflow, therefore this is not a duplicate question.
The reason why I am instantiating the controller class is that I want to pass some parameters so that these parameters will be displayed in GUI.
I am loading an FXML file the following way:
/*
* for Work Order button
*/
@FXML
private void pressWorkOrder() throws Exception{
WorkOrderController wo = new WorkOrderController("ashdkjhsahd"); //instantiating constructor
Parent parent = FXMLLoader.load(getClass().getResource("/fxml/WorkOrder.fxml"));
Scene scene = new Scene(parent);
Stage stage = new Stage();
stage.setScene(scene);
stage.setTitle("Word Order");
stage.setResizable(false);
stage.show();
}
And here is my actual Controller class:
public class WorkOrderController implements Initializable{
@FXML
private Button summary;
private String m,n;
public WorkOrderController(String str) {
// TODO Auto-generated constructor stub
m = str;
}
//for testing
public void set(String str){
m = str;
}
@FXML
public void check(){