Tuesday, May 22, 2012

Create AnchorPane using FXML

javafx.scene.layout.AnchorPane allows the edges of child nodes to be anchored to an offset from the anchorpane's edges. If the anchorpane has a border and/or padding set, the offsets will be measured from the inside edge of those insets.

Modify Sample.fxml in the last article "Create GridPane using FXML" to replace GridPane with AnchorPane.

<?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.*?>

<AnchorPane fx:controller="javafxml.Sample" xmlns:fx="http://javafx.com/fxml"
    prefHeight="200" prefWidth="400" >

        <Text text="java-Buddy" AnchorPane.topAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
        <Label text="Who are you?" AnchorPane.topAnchor="25.0" AnchorPane.leftAnchor="0.0"/>
        <TextField id="textfield" fx:id="textfield" AnchorPane.topAnchor="25.0" AnchorPane.rightAnchor="0.0"/>
        <Button id="button"  text="Click Me!"
            onAction="#handleButtonAction" fx:id="button" 
            AnchorPane.topAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
        <Label id="label" fx:id="label" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"/>
        
</AnchorPane>


AnchorPane



No comments:

Post a Comment