Java Reference
In-Depth Information
The custom component we define here is a simple composite custom component, meaning that it is composed
of several nodes that together fulfill some business requirement. The custom component we create in this example is
called ProdId . It's designed to help with data entry of product ID that must have the form “A-123456” where there is
only one character before the dash, and it must be “A” or “B” or “C.” There could be up to six characters after the dash.
This program is shown in Listings 3-26 to 3-28.
Listing 3-26. ProdId.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<fx:root type="javafx.scene.layout.HBox"
alignment="BASELINE_LEFT"
maxHeight="-Infinity"
maxWidth="-Infinity"
minHeight="-Infinity"
minWidth="-Infinity"
xmlns=" http://javafx.com/javafx/8 "
xmlns:fx=" http://javafx.com/fxml/1 " >
<children>
<TextField fx:id="prefix" prefColumnCount="1"/>
<Label text="-"/>
<TextField fx:id="prodCode" prefColumnCount="6"/>
</children>
</fx:root>
Listing 3-27. ProdId.java
package projavafx.customcomponent;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import java.io.IOException;
public class ProdId extends HBox {
@FXML
private TextField prefix;
@FXML
private TextField prodCode;
private StringProperty prodId = new SimpleStringProperty();
 
Search WWH ::




Custom Search