Send a object to other screen in javafx - java

I'm new in the javafx and until now is going good. But I don't find any form to send a object from a screen to another. I have some dificult to understand funciont od annotations #FXML and the method initialize from Initializable interface
Class that calls another
public class FluxoCaixaController extends ParametrosTelas implements iTelaPrincipalFX {
/*Atributos locais*/
private ObservableList<String> opcoes = FXCollections.observableArrayList("Receita", "Despesa");
private Object parent;
private AberturaDeTelasFX formaAbertura;
private ToggleGroup modalGroup = new ToggleGroup();
private Categoria categoria;
private CategoriaTreeViewController root = new CategoriaTreeViewController();
#Override
public void showScreen() {
formaAbertura = new AberturaDialogFX();
formaAbertura.loadFXML(bundle, icone, bundle.getString("screnn.fluxo.title"), new AnchorPane(), "FluxoCaixa.fxml");
}
#Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
tipoField.getItems().setAll(opcoes);
root.setParentController(getInstance());
//idColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
//descricaoColumn.setCellValueFactory(new PropertyValueFactory<>("descricao"));
//atualizaTabela();
}
#FXML
private void btnAddCetegoria() {
root.showScreen();
categoriaSubcategoriaField.setText(categoria.getDescricao());
}
private Object getInstance(){
return this;
}
Class called
public class CategoriaTreeViewController extends ParametrosTelas implements iTelaNormalFX {
private AberturaDeTelasFX formaAbertura;
private Object parent;
private CategoriaService categoriaService = new CategoriaService();
#FXML
private TreeView<Categoria> treeView;
private Categoria EmptyCategoria;
private TreeItem<Categoria> rootItem;
private EventHandler<MouseEvent> mouseEventHandle;
#Override
public void showScreen() {
formaAbertura = new AberturaDialogFX();
formaAbertura.loadFXML(bundle, icone, bundle.getString("screnn.subcategory.title"), new AnchorPane(), "CategoriaTreeView.fxml");
}
#Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
initialiazeTree();
mouseEventHandle = (MouseEvent event) -> {
handleMouseClicked(event);
};
treeView.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEventHandle);
treeView.setRoot(rootItem);
}
private void initialiazeTree() {
EmptyCategoria = new Categoria();
EmptyCategoria.setDescricao("Categorias");
rootItem = new TreeItem<>(EmptyCategoria);
// private TreeItem<SubCategoria> itens = new TreeItem<>();
for (Categoria g : categoriaService.listaCategorias()) {
List<Categoria> subLst = categoriaService.listaSubCategoriasByCategoria(g.getId());
TreeItem<Categoria> itens = new TreeItem<>(g);
//ObservableList<Categoria> subData = FXCollections.observableArrayList(subLst);
for (Categoria s : subLst) {
s.setCategoria(g);
TreeItem<Categoria> subItem = new TreeItem<>(s);
//subItem.addEventHandler(MouseEvent, new EventHandler<MouseEvent>() {
itens.getChildren().add(subItem);
}
//itens.getChildren().add(itens);
rootItem.getChildren().add(itens);
}
}
private void handleMouseClicked(MouseEvent event) {
if (treeView.getSelectionModel().getSelectedItem() != null) {
Categoria name = (Categoria) ((TreeItem) treeView.getSelectionModel().getSelectedItem()).getValue();
FluxoCaixaController fluxo = (FluxoCaixaController) getParentController();
fluxo.setCategoria(name);
System.out.println("Node click: " + name.getDescricao());
formaAbertura.getStage().hide();
}
/*Node node = event.getPickResult().getIntersectedNode();
// Accept clicks only on node cells, and not on empty spaces of the TreeView
if (node instanceof Text || (node instanceof TreeCell && ((TreeCell) node).getText() != null)) {
String name = (String) ((TreeItem)treeView.getSelectionModel().getSelectedItem()).getValue();
System.out.println("Node click: " + name);
}*/
}
}
Must of the interfaces just point to on or two methods. The AberturaDeTelasFX interface has a Implementation that says how the screen should open.
AberturaNormalFX
public class AberturaNormalFX implements AberturaDeTelasFX {
private Stage stage;
#Override
public void loadFXML(ResourceBundle bundle, Image icon, String title, Node node, String fxmlPath) {
try {
// Carrega o root layout do arquivo fxml.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass()
.getResource(fxmlPath));
loader.setResources(bundle);
if (node instanceof BorderPane) {
BorderPane rootLayout = (BorderPane) loader.load();
showLayout(icon, title, rootLayout);
} else if (node instanceof AnchorPane) {
AnchorPane rootLayout = (AnchorPane) loader.load();
showLayout(icon, title, rootLayout);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void showLayout(Image icone, String title, Parent node) {
stage = new Stage();
Scene scene = new Scene(node);
stage.setTitle(title);
stage.getIcons().add(icone);
stage.setScene(scene);
stage.show();
}
#Override
public void loadFXML(String title, Node node, String fxmlPath) {
throw new UnsupportedOperationException("Not supported yet."); //To chan
ge body of generated methods, choose Tools | Templates.
}
/**
* #return the stage
*/
#Override
public Stage getStage() {
return stage;
}
}

Looking on your code I did not find a class, which extends Application.
In my project, which I built recently, I used it as a part of the Presentation layer, kind of a bridge between controllers (which represent Controller layer), where each controller manages a single screen. Consider following example:
public class MainAppFX extends Application {
// The primary window or frame of this application
private Stage primaryStage;
this 'patient' represents object from your controller:
private PatientData patient;
/**
* Default constructor
*/
public MainAppFX() {
super();
}
/**
* The application starts here
*
* #param primaryStage
* #throws Exception
*/
#Override
public void start(Stage primaryStage) throws Exception {
log.info("Program loads");
// The Stage comes from the framework so make a copy to use elsewhere
this.primaryStage = primaryStage;
// Create the Scene and put it on the Stage
loadPatientParentWindow();
// Set the window title
this.primaryStage.setTitle("Your Window title");
this.primaryStage.show();
}
/**
* Loads Patient FXML layout
* This method loads one of your screens
*/
public void loadPatientParentWindow() {
try {
// Instantiate the FXMLLoader
FXMLLoader loader = new FXMLLoader();
// Set the location of the fxml file in the FXMLLoader
loader.setLocation(MainAppFX.class.getResource("/fxml/PatientForm.fxml"));
// Parent is the base class for all nodes that have children in the
// scene graph such as AnchorPane and most other containers
Parent parent = (AnchorPane) loader.load();
// Load the parent into a Scene
Scene scene = new Scene(parent);
// Put the Scene on Stage
primaryStage.setScene(scene);
// Give the PatientFXMLController controller access to the main app.
PatientFXMLController controller = loader.getController();
below is the setter method of Patient controller, where it gets an access to the Main class
controller.setMainAppFX(this);
} catch (IOException | SQLException ex) { // getting resources or files could fail
log.error(null, ex);
System.exit(1);
}
}
/**
* Setter for PatientData object in the Main class
you use it in the controller class
*
* #param patient
*/
public void setPatient(PatientData patient) {
this.patient = patient;
}
/**
* Getting PatientData object from the Main class
*
* #return
*/
public PatientData getPatient() {
return patient;
}
/**
* Where it all begins
*
* #param args command line arguments
*/
public static void main(String[] args) {
launch(args);
System.exit(0);
}
}
And here is one of the controller classes, which represent one of the screens:
public class PatientFXMLController {
Reference to the main application starts here
private MainAppFX mainApp;
Next object you will be passing to the main class using setters
private PatientData patient;
// The #FXML annotation on a class variable results in the matching
// reference being injected into the variable
// label is defined in the fxml file
// Bunch of #FXML annotations with respective fields (you can get them from SceneBuilder)
#FXML
private TextField patientIdField;
#FXML
private TextField lastNameField;
// so on...
/**
* The constructor. The constructor is called before the initialize()
* method. You don't need to call it. It's being called by automatically
*/
public PatientFXMLController() {
super();
Create empty Patient object for initialize method
patient = new PatientData();
}
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded. Useful if a control must be
* dynamically configured such as loading data into a table.
*/
#FXML
private void initialize() {
log.info("initialize called");
// Initializing form fields
Bindings.bindBidirectional(patientIdField.textProperty(), patient.patientIdProperty(), new NumberStringConverter());
// so on .....
}
/**
* Loads Another screen
this method below represents an action for a button, which leads to another screen, and where you passing an object from this controller to the main class. And then you can pass this object from main class to anotherScreen controller, since you will have its loadAnotherScreenWindow() method there
*
* #param event
*/
#FXML
private void loadAnotherScreen(ActionEvent event) throws SQLException {
Passing Patient object to the main class so it can be used in Another screen controller to get related inpatients
mainApp.setPatient(patient);
}
/**
* Is called by the main application to give a reference back to itself.
* This class receives the reference of the main class.
*
* #param mainApp
*/
public void setMainAppFX(MainAppFX mainApp) {
this.mainApp = mainApp;
}
/**
* Setter for PatientData object
*
* #param patient
*/
public void setPatient(PatientData patient) {
this.patient = patient;
}
}

Related

#FXML Annotation not working correctly

I'm currently working on a 'small' project with JavaFX. I used the SceneBuilder to create the first sketch of my GUI. it still needs some adjustment and styling but I wanted to see if it's working so far.
I have 2 hyperlinks on the GUI, if the user clicks one of them the default system-browser should open with a specific URL.
So far I got this:
Main.java:
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws MalformedURLException, IOException {
DataBean dataBean= new DataBean(primaryStage);
Controller controller = new Controller(dataBean);
controller.show();
}
public static void main(String[] args) {
launch(args);
}
}
DataBean.java:
public class DataBean {
private Stage primaryStage;
public DataBean(Stage stage) {
primaryStage = stage;
}
public Stage getPrimaryStage() {
return primaryStage;
}
}
TestautomatView.java:
public class TestautomatView implements Initializable {
#FXML
private ComboBox<String> environmentCombo;
#FXML
private Hyperlink crhl;
#FXML
private Hyperlink help;
#Override
public void initialize(URL location, ResourceBundle resources) {
}
private Scene scene;
private BorderPane root;
public TestautomatView() throws MalformedURLException, IOException {
root = FXMLLoader.load(new URL(TestautomatView.class.getResource("Sample.fxml").toExternalForm()));
scene = new Scene(root);
}
public void show(Stage stage) {
stage.setTitle("CrossReport Testautomat");
stage.setScene(scene);
stage.show();
}
public ComboBox<String> getEnvironmentCombo() {
return environmentCombo;
}
public Hyperlink getCrhl() {
return crhl;
}
public Hyperlink getHelp() {
return help;
}
public Scene getScene() {
return scene;
}
}
In my controller I want to set the ActionHandler to the hyperlinks but it's not working because the getters in my view return null.
public class Controller {
private DataBean dataBean;
private TestautomatView view;
public Controller(DataBean databean) throws MalformedURLException, IOException {
this.dataBean = databean;
this.view = new TestautomatView();
setActionHandlers();
}
public void show() throws MalformedURLException, IOException {
view.show(dataBean.getPrimaryStage());
}
private void setActionHandlers() {
// setHyperlink(view.getCrhl(), "www.example.com");
// setHyperlink(view.getHelp(), "www.example2.com");
}
private void setHyperlink(Hyperlink hl, String uri) {
hl.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
//TODO - Open Default Browser
}
});
}
}
When I start my application, I can see the GUI but when I want to add the ActionHandlers I get a NullPointerException.
In the ´Sample.fxml´ file the hyperlinks are children of a HBox
<Hyperlink fx:id="crhl" text="Report" />
<Hyperlink fx:id="help" text="Help" />
But it's not just the hyperlinks even the ComboBox is null when I inspect my app in the debugger.
Where is my mistake?
The problem is that you are creating your controller manually by using new TestautomatView(). It must be created by FXMLLoader for annotations to work. You must also set fx:controller attribute in Sample.fxml to your controller (TestautomatView) fully qualified class name.
Example code:
FXMLLoader fl = new FXMLLoader(new URL(TestautomatView.class.getResource("Sample.fxml").toExternalForm()));
root = fl.load();
TestautomatView controller = fl.getController();
PS: You should rename your TestautomatView to TestautomatController. FXML file is your "view".
As pointed out in another answer, the issue is that you create an instance of TestautomatView "by hand". The default behavior of the FXMLLoader is to create an instance of the controller class specified in the FXML file, and use that instance as the controller. Consequently, you have two instances of TestautomatView: the one you created (and have a reference to), and the one that was created by the FXMLLoader. It is the second one that has the #FXML-annotated fields initialized.
You can change this default behavior by creating an FXMLLoader instance, and setting the controller on it directly. E.g. consider doing:
public class TestautomatView implements Initializable {
#FXML
private ComboBox<String> environmentCombo;
#FXML
private Hyperlink crhl;
#FXML
private Hyperlink help;
#Override
public void initialize(URL location, ResourceBundle resources) {
}
private Scene scene;
private BorderPane root;
public TestautomatView() throws MalformedURLException, IOException {
FXMLLoader loader = new FXMLLoader(TestautomatView.class.getResource("Sample.fxml"));
loader.setController(this);
root = loader.load();
scene = new Scene(root);
}
// etc...
}
Since you are directly setting the controller, you need to remove the fx:controller attribute from the Sample.fxml file for this to work.
You may also be interested in this pattern, which is quite similar (though not exactly the same) as what you are trying to do here.

JavaFX - Objects stuck in the memory

I have a huge application built using JavaFX,, as there are a lot of stages to show i created a class to load views [more like utils class] called FXMLManager(i think the problem is there),, To show a single stage i should create an instance of FXMLManager,, after the stage is closed FXMLManager instances remains in the memory,,, i tried setting the object to null after the stage is closed with no luck..
FXMLManager.java:
public class FXMLManager<T extends AbstractController> {
/**
*
*/
private static ClassLoader cachingClassLoader = new FXMLlightweightLoader(FXMLLoader.getDefaultClassLoader());
private final Class<T> clazzType;
#Getter private T controller;
private FXMLLoader fxmlLoader;
#Getter private Parent root;
public FXMLManager(Class<T> clazz) {
this.clazzType = clazz;
Annotation annotation = this.clazzType.getAnnotation(FXMLController.class);
if (annotation == null)
throw new NullPointerException(
"controller type provided is not annotated with FXMLController : " + clazzType);
FXMLController fxmlController = (FXMLController) annotation;
this.fxmlLoader = constructFXMLLoader();
this.fxmlLoader.setLocation(getURL(fxmlController.value()));
try {
AbstractController abstractController = (AbstractController) clazzType.newInstance();
this.fxmlLoader.setController(abstractController);
this.root = (Parent) this.fxmlLoader.load();
} catch (Exception e) {
e.printStackTrace();
}
this.controller = this.fxmlLoader.getController();
}
private FXMLLoader constructFXMLLoader() {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setClassLoader(cachingClassLoader);
fxmlLoader.setResources(I18NSupport.getBundle());
return fxmlLoader;
}
public T getController(Class<T> controllerType) {
T controller = controllerType.cast(this.fxmlLoader.getController());
return controller;
}
public static URL getURL(String url) {
return FXMLManager.class.getResource(url);
}
private Stage stage;
public Stage getStage(String title) {
if (stage == null) {
Scene scene = new Scene(this.root);
stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
stage.setScene(scene);
stage.getIcons().add(ImageLoader.loadImage("icon"));
}
stage.setTitle(title);
return stage;
}
}
i am using FXMLManager as follows:
public static void openRandomForm() {
FXMLManager<Controller> fxmlManager = new FXMLManager<>(Controller.class);
//fxmlManager.getController(); do stuff with the controller
Stage stage = fxmlManager.getStage("title");
stage.showAndWait();
fxmlManager = null;
}
Am i doing something wrong? as far as i know FXMLManager should be cleared,, no?
Screen shots of heap dump after showing couple of stages then performing GC:

javafx tableview does not show content

I recently started programming with JavaFx. I have the following Problem:
I am writing a controller class, in which I hava a Table with orders, but the content can only be set in the initialize method.
The List with orders should be set in the orderTable with the method setorderList. The problem is that the Orders are not shown in the TableView.
I have already tried to trigger an update of the TableView by removing the items of the Table and filling them up again.
For test purposes i created the orderList with a test-order in the initialize() method and set them to the table with orderTable.setItems(orderList). When i did this it worked perfectly.
So the order from the initialize method (with number 23) is shown in the Table but the List thats set in setOrderList is not.
This confuses me, because it seems like the orderTable.setItems(orderList) Statement only works in the initialize() method.
Here is my code:
public class OrderOverviewController implements Initializable{
#FXML
private TableView<Order> orderTable;
#FXML
private TableColumn<Order,Integer> orderNumberColumn;
private ObservableList<Order> orderList;
private OrderDao orderDao;
#Override
public void initialize(URL location, ResourceBundle resources) {
orderNumberColumn.setCellValueFactory(new PropertyValueFactory<>("orderId"));
orderList=FXCollections.observableArrayList();
//ordernumber and Current user
orderList.add(new Order(23,null));
orderTable.setItems(orderList);
}
public void setOrderList(ObservableList<Order> orderList) {
orderTable.setItems(orderList);
}
}
This is the start method of the main class where i setup the scenes for my application. First the LoginN.fxml gets loaded, and the mainScene is only set up. After this the LoginManager gets created.
#Override
public void start(Stage primaryStage) throws IOException {
this.stage=primaryStage;
Parent root = FXMLLoader.load(getClass().getResource("/view /LoginN.fxml"));
loginScene=new Scene(root);
primaryStage.setScene(loginScene);
primaryStage.show();
root=null;
root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
mainScene=new Scene(root);
new LoginManager(this);
}
So here is my LoginManager which has an static instance of itself, so i can access it easier.
The method setLoggedInUser sets the user after the login procedure as you can see in the next code sample which contains the method login.
Here i get all orders of the user, with which i call then the setOrderMethod of the controller where my Problem with the table is.
public class LoginManager {
private static LoginManager loginManager;
private Main main;
private User loggedInUser;
private OrderDao orderDao;
private MainController mainController;
private OrderOverviewController ooc;
public LoginManager(Main main){
loginManager=this;
this.main=main;
}
public static LoginManager getInstance(){
return loginManager;
}
public void setMainView(){
main.setMainView();
}
public void setLoggedInUser(User loggedInUser) {
this.loggedInUser = loggedInUser;
//load OrderViewController to set Previous orders
try {
URL location=getClass().getResource("/view/Orders.fxml");
FXMLLoader loader=new FXMLLoader();
loader.setLocation(location);
loader.setBuilderFactory(new JavaFXBuilderFactory());
Parent root=(Parent)loader.load(location.openStream());
orderDao=new OrderDao();
ooc=loader.getController();
ooc.setOrderList(orderDao.getOrdersOfUser(loggedInUser));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Here is the login method of the LoginController which gets triggered when the loginButton is pressed:
public void login() throws Exception{
userName=usernameField.getText();
password=AESCrypt.encrypt(passwordField.getText());
if(userdao.isUserValid(userName, password))
{
LoginManager.getInstance().setMainView();
LoginManager.getInstance().setLoggedInUser(userdao.getUserByName(userName));
}
else
errorLabel.setText("Login failed!");
}
If the userData was valid the mainScene gets set up with the LoginManager and the logged in user is set.
This is how i included the Orders.fxml (The view of the OrderOverviewController) in a Tab in the Main view:
<fx:define>
<fx:include source="Orders.fxml" fx:id="orderOverviewContent"/>
</fx:define>
<Tab content="$orderOverviewContent" text="Order Overview" />
Thank you for your help.

Set Reference Application from Controller?

New to JAVAFX so this maybe a simple fix, but I have controllers in my application setup using FXML files. I reference the controller to use via the FXML file and to load the file i use the following code in my Application class
private void replaceScene(String resource) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(resource));
Pane screen = (Pane) loader.load();
Scene scene = new Scene(screen);
scene.getStylesheets().addAll(getClass().getResource("/css/application.css").toExternalForm());
stage.setScene(scene);
stage.sizeToScene();
IControlledScreen controller = (IControlledScreen) loader.getController();
controller.setApp(this);
} catch (Exception e) {
System.out.println("Cannot load resource " + resource);
System.out.println(e.getMessage());
}
}
And here is a basic controller
public class MyController implements IControlledScreen {
MyApplication app;
public void setApp(MyApplication application) {
app = application;
}
#FXML
public Button btnStart;
// Initialises the controller class.
#FXML
protected void initialize() {
btnStart.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent arg0) {
// code here
}
});
}
}
I have also got an interface called IControlledScreen to set the reference to the application
public interface IControlledScreen {
// ALlows us a reference to the application
public void setApp(MyApplication app);
}
Now this all works fine, until i try to access the app variable during the initialize event. So changing the above controller to this now breaks, because app = NULL.
public class MyController implements IControlledScreen {
MyApplication app;
public void setApp(MyApplication application) {
app = application;
}
#FXML
public Button btnStart;
// Initialises the controller class.
#FXML
protected void initialize() {
// HERE app = NULL
app.GetSomeProperty = "";
}
}
How can i get round this?
Well I think you have to change your design.
The initialize method is called during FXMLLoader.load()
So the call stack would be something like
..replaceScene
..loader.load
....MyController.initialize()
..loader.getController
..controller.setApp(app)
If you really have to access the application from inside your controller you would need to make it a singleton.

Add data to static ComboBox in JavaFX 2.2

I just can't figure out how to add data to static ComboBox in JavaFX 2.2. Whatever I try to do ComboBox is empty. Here is the code:
#FXML private MenuItem menuItemNewTile;
#FXML private static ComboBox<Tile> comboBoxTileList;
#FXML
private void menuItemNewTileSetOnAction(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource(TILE_WINDOW_URL));
Scene scene = new Scene(root);
Stage tileStage = new Stage();
tileStage.setScene(scene);
tileStage.show();
}
#FXML
private void comboBoxTileListSetOnAction(ActionEvent event) {
}
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
comboBoxTileList = new ComboBox<>();
}
public static void refreshTileList(Tile tile) {
comboBoxTileList.getItems().add(tile);
}
If ComboBox is private, and I add item in initialize method it's working, but with static ComboBox I tried million things and still no progress.
Solution
Don't use static and #FXML together.
Rework your design so that the static keyword is no longer required for the comboBoxTileList and use an instance variable instead.
Additional Issue
An #FXML member such as comboBoxTileList should never be set to a new value, so you should not have comboBoxTileList = new ComboBox<>();
Answer to additional questions
I use another window to create new Tile object and from controller class of that window i call refreshTileList method. How to do that without using static?
There are numerous ways of writing your code so that you don't need a static reference to controller members. Here is a sample based on a solution from: Passing Parameters JavaFX FXML. You will need to modify the example to fit your exact case, it's just presented to demonstrate a possible pattern that you could use.
You can construct a new controller in code, passing any parameters you want from your caller into the controller constructor. Once you have constructed a controller, you can set it on an FXMLLoader instance before you invoke the load() instance method.
To set a controller on a loader (in JavaFX 2.x) you CANNOT also define a fx:controller attribute in your fxml file.
class ComboController {
#FXML private static ComboBox<Tile> comboBoxTileList;
public void refreshTileList(Tile tile) {
comboBoxTileList.getItems().add(tile);
}
}
class AnotherController {
#FXML private Button createTile;
#FXML private Button newCombo;
#FXML private StackPane mainPane;
private comboController;
#FXML private void createTile(ActionEvent event) {
if (comboController == null) {
return;
}
comboController.refreshTileList(
new Tile()
);
}
#FXML private void newCombo(ActionEvent event) {
try {
comboController = new ComboController();
FXMLLoader loader = new FXMLLoader(
getClass().getResource(
"combo.fxml"
)
);
loader.setController(comboController);
Pane comboPane = (Pane) loader.load();
mainPane.getChildren().setAll(comboPane);
} catch (IOException e) {
// handle exception.
}
}
}

Categories