new components. Here is a skeleton class for just a component. This class both loads the FXML to
create the meat of the component as well as acting as the controller for the component. In order to
use it we should:
• Rename the class to be the name of the component we wish to define.
• Point to the correct FXML file
• Do not include a controller definition in the FXML file
• Define the root of the FXML file as <fx:root>
package com.kolban;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane;
/**
*
* @version 2014-05-04
*/
public class SampleComponent extends AnchorPane {
/**
* General constructor for this component.
*/
public SampleComponent() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml/SampleComponent.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (Exception e) {
e.printStackTrace();
}
} // End of SampleComponent
/**
* Initialize the component.
*/
@FXML
private void initialize() {
// Code here
} // End of initialize
} // End of class
// End of file
JavaFX 3
rd
Party Packages
ControlsFX
ControlsFX is a collection of components for JavaFX. It can be found here:
http://fxexperience.com/controlsfx/
org.controlsfx.dialog.Dialogs
Arguably one of the most compelling features of this package is the rich set of dialogs that it
provides. To best understand the dialog, imagine it broken into a set of parts:
• title – The area on the title bar of the dialog
Page 286
Kommentare zu diesen Handbüchern