Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to modularize a JavaFX application?

I've started toying with JavaFX 2 and I really like the ease with which one can create a UI with FXML. However, once you get past the basic examples and you need a UI with many windows, it seems illogical to have the definition for the whole application's UI in a single FXML file.

Is it possible to write separate components in separate FXML files and then include them as needed? Say for example that I wanted a window to popup when the user clicks on an item from the main menu; could I write the definition for that window in a separate FXML file, load it at runtime and add it to the node tree?

like image 268
corbenik Avatar asked Oct 06 '22 11:10

corbenik


1 Answers

From FXML perspective there are two approaches:

  1. Simply use fx:include directive to split application into logical parts in different fxml files.

  2. More advanced way would be to implement parts of your application as separate "controls". Which will have their own (can be very simple) API to provide data and can be used in FXML or FX API like built-in controls. See next question for details how to implement that using FXML: How to pass object created in FXML Controller1 to Controller2 of inner FXML control

like image 55
Sergey Grinev Avatar answered Oct 14 '22 02:10

Sergey Grinev