Sunday, May 20, 2012

Create GridPane using FXML

javafx.scene.layout.GridPane lays out its children within a flexible grid of rows and columns.

GridPane using FXML

Modify Sample.fxml and from the auto generated files described in the article "JavaFX FXML Application".

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

<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.textfield.*?>

<GridPane fx:controller="javafxml.Sample" xmlns:fx="" 
    prefHeight="200" prefWidth="320"
    alignment="center" hgap="10" vgap="10">

        <Text text="java-Buddy"
            GridPane.columnIndex="0" GridPane.rowIndex="0"
        <Label text="Who are you?"
            GridPane.columnIndex="0" GridPane.rowIndex="1"/>
        <TextField id="textfield" fx:id="textfield"
            GridPane.columnIndex="1" GridPane.rowIndex="1"/>
        <Button id="button"  text="Click Me!" 
            onAction="#handleButtonAction" fx:id="button"
            GridPane.columnIndex="0" GridPane.rowIndex="2"/>
        <Label id="label" fx:id="label"
            GridPane.columnIndex="1" GridPane.rowIndex="2"/>

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package javafxml;

import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

 * @web
public class Sample implements Initializable {
    private Label label;
    private TextField textfield;
    private void handleButtonAction(ActionEvent event) {
        System.out.println("You clicked me!");
        label.setText("Hello  " + textfield.getText());
    public void initialize(URL url, ResourceBundle rb) {
        // TODO

- Create BorderPane using FXML
- Create FlowPane using FXML
- Create AnchorPane using FXML

No comments:

Post a Comment