7 Replies Latest reply: Jun 4, 2012 11:43 AM by 941486 RSS

    difference between .fx .fxml and .java

    941486
      I am new to javafx , i have found files with extension .fx,.fxml,.java , i have successfully ran many javafx samples that has extension .java . my question is what is the difference between .fx,.fxml,.java
      thanks in advance
        • 1. Re: difference between .fx .fxml and .java
          885691
          .fx files contain FXScript code. They were used in JavaFX 1.x and are no longer supported.

          .fxml files are XML documents used in JavaFX 2.0 and later to define the layout of a JavaFX application. They are essentially a serialized representation of an object hierarchy (generally a scene graph). They allow you to define the structure of your user interface declaratively rather than programmatically (i.e. in Java code).

          Hope this helps.

          Greg
          • 2. Re: difference between .fx .fxml and .java
            941486
            is it mandatory to include GUI components in .fxml file or else we can include them in .java file it self ?

            Edited by: 938483 on Jun 4, 2012 7:26 AM
            • 3. Re: difference between .fx .fxml and .java
              885691
              FXML is not mandatory. It can be quite convenient, but you are not required to use it.
              • 4. Re: difference between .fx .fxml and .java
                daniel
                Note that you can graphically create and edit FXML files using the JavaFX SceneBuilder.
                You can download the JavaFX SceneBuilder preview from here:
                http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html

                hope this helps,

                -- daniel
                • 5. Re: difference between .fx .fxml and .java
                  941486
                  thanks daniel ya i have watched the tutorial for JavaFX Scene Builder but i didnot found tutorial on how to hook up the GUI components developed using Scene Builder with java code, where i can find them ??
                  thanks in advance

                  Edited by: 938483 on Jun 4, 2012 8:15 AM

                  Edited by: 938483 on Jun 4, 2012 8:15 AM
                  • 6. Re: difference between .fx .fxml and .java
                    daniel
                    Hi,

                    You connect the UI built in FXML with your Java code by associating a controller class (that you write) with your FXML.
                    For each FXML object you want to access in your code, you define an instance variable in your controller class, which you tag with the @FXML annotation.
                    Then you add an fx:id to your object in FXML (Properties section of the inspector in the scene builder) - the value of the fx:id must be the name of the instance variable in the controller code.

                    See this thread: Re: problem in scene builder for some more details.

                    Note that the SceneBuilder tutorial does speak of this.
                    I would also advise to download the SceneBuilder samples (same page than for SceneBuilder download), and have a look at the HelloWorld sample, which shows how to get access to a simple button defined in FXML within your own Java code.

                    Hope this helps,

                    -- daniel
                    • 7. Re: difference between .fx .fxml and .java
                      941486
                      thanks daniel...!!!! your post helped me a lot