Menu

Create a JavaFX Stage

Ralph

You need a JavaFX stage to display controls and shapes to the screen.

You can build a stage programatically or you can use the Scene Builder to create a FXML file.

We prefer to use the Scene Builder.

In the FXML file you have to name the controls with a fx:id. You have also to name a controller. This controller is the link between the FXML file and the view object.

Here is an example of a contract view (ContractList.fxml):

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<?import java.net.*?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hoppe.extra.person.PersonListController">
   <center>
    <TableView fx:id="personTableView" GridPane.hgrow="ALWAYS" editable="true">
      <columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
      <columns>
        <TableColumn fx:id="search" text="%personList.search" editable="false" />
text="%personList.id" />
      </columns>
    </TableView>
   </center>
   <bottom>
      <HBox alignment="CENTER_RIGHT" layoutY="24.0" prefHeight="25.0">
         <padding>
            <Insets bottom="5.0" left="5.0" right="10.0" top="5.0" />
         </padding>
         <children>
            <Button mnemonicParsing="false" text="%personList.new" />
         </children>
      </HBox>
   </bottom>

    <stylesheets>
        <URL value="@/css/PersonList.css" />
    </stylesheets>

</BorderPane>

Please take notice of the fx:controller. This is the missing link to the framework.


Next step is to [Create a Controller].


Related

Wiki: Create a Controller
Wiki: Create a View Object