FXML ist die XML-basierte Oberflächenbeschreibungssprache in JavaFX seit Version 2.0, vergleichbar mit XAML in WPF und Silverlight.
Hello World in FXML
<?import javafx.scene.control.Label?>
<Label text="Hallo Welt!"/>
Zweites Beispiel
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import fxml.MyGroup?>
<Gruppe xmlns:fx="http://javafx.com/fxml">
<children>
<Button text="Klick mich" onAction="#handleButtonAction" />
<Label fx:id="label" translateX="0" translateY="30" text=""/>
</children>
</Gruppe >
package fxml;
import java.net.URL;
import java.util.Map;
import javafx.event.ActionEvent;
import javafx.fxml.Bindable;
import javafx.fxml.FXML;
import javafx.fxml.Resources;
import javafx.scene.Group;
import javafx.scene.control.Label;
public class Gruppe extends Group implements Bindable{
@FXML private Label label;
@FXML private void handleButtonAction(ActionEvent event) {
label.setText("Hallo Welt!");
}
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
}
}