This discussion is archived
2 Replies Latest reply: Jan 10, 2013 10:55 AM by biochemistry43 RSS

Handling Events in FXML-includes

J. Ishikawa Newbie
Currently Being Moderated
Hi!

I am using FXML to define the GUI of my application. As the GUI is pretty complex with many regions and items in it, I have created a separate FXML file for each main region to reduce the overall complexity of maintaining the design.

My parent FXML file, called "Frame.xml", includes those "sub-regional" FXML-definitions using "<fx:include source="RegionXYZ.fxml" />".

What I am now stucked with is, how to handle events in this approach...

Questions:
a) Can I add a separate controller in each of the "sub-regional" FXML-files, like "fx:controller="FXMLRegionXYZController"?
b) Or must I, or even should I, use only a single controller inside the main FXML? Will this single controller be able to recognize and handle actions/events in the included FXML-definitions as well?
c) What is the best approach in general for this?

Thanks,
Jörn
  • 1. Re: Handling Events in FXML-includes
    984080 Explorer
    Currently Being Moderated
    Hi,

    Since javafx 2.2 their is an improvement for sub-controllers:
    check: http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm

    an example:
    <VBox fx:controller="com.foo.MainController"> 
    ...
        <fx:include fx:id="dialog" source="dialog.fxml"/>
    ...
    </VBox>
    
    public class MainController extends Controller { 
        @FXML private Window dialog;
        @FXML private DialogController dialogController;
    
        ...
    }
    A second aproach is to not use the include, but rather use the FXMLloader, to load to UI child object + controller and attach it to the desired parent object.
  • 2. Re: Handling Events in FXML-includes
    biochemistry43 Newbie
    Currently Being Moderated
    Hi!

    I am using FXML to define the GUI of my application. As the GUI is pretty complex with many regions and items in it, I have created a separate FXML file for each main region to reduce the overall complexity of maintaining the design.

    My parent FXML file, called "Frame.xml", includes those "sub-regional" FXML-definitions using "<fx:include source="RegionXYZ.fxml" />".

    What I am now stucked with is, how to handle events in this approach...

    Questions:
    a) Can I add a separate controller in each of the "sub-regional" FXML-files, like "fx:controller="FXMLRegionXYZController"?
    - Yes, you can

    b) Or must I, or even should I, use only a single controller inside the main FXML? Will this single controller be able to recognize and handle actions/events in the included FXML-definitions as well?
    - if you could control everything from a single controller but you option (A) is much better


    c) What is the best approach in general for this?
    - Option (a)



    Thanks,
    Jörn

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points