- Herunterladen von Gluon scene-builder
- Installieren von e(fx)clipse in eclipse
- Window -> Preferences -> JavaFx -> Scene Builder path setzen
- Main.java
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("HelloWorld.fxml"));
Scene scene = new Scene(root);
stage.setTitle("Hello World");
stage.setScene(scene);
stage.show();
}
}
- MainStageController.java
package application;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
public class MainStageController {
@FXML
Button myButton;
@FXML
TextField myTextField;
public void initialize() {
myButton.setOnAction(e -> {
myTextField.setText("hello world");
});
}
}
- HelloWorld.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="259.0" prefWidth="425.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainStageController">
<children>
<AnchorPane prefHeight="208.0" prefWidth="600.0">
<children>
<Button fx:id="myButton" alignment="BOTTOM_LEFT" layoutX="171.0" layoutY="220.0" mnemonicParsing="false" text="Hello World!" />
<TextField fx:id="myTextField" editable="false" layoutX="138.0" layoutY="117.0" />
</children>
</AnchorPane>
</children>
</StackPane>