Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JavaFX Simple FXML-Controler Sample
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="100.0" prefWidth="320.0" xmlns:fx="" fx:controller="FormController">
<HBox alignment="CENTER" prefHeight="32.0" prefWidth="320.0" spacing="20.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<TextField fx:id="field" prefWidth="200.0" />
<Button fx:id="button" onAction="#handleAction" text="Submit" />
<Label fx:id="label" minHeight="16.0" minWidth="69.0" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="40.0" />
<URL value="@formstyle.css" />
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class FormController implements Initializable {
private TextField field;
private Label label;
private void handleAction(ActionEvent event) {
// TextFiled から文字列を取得
String text = field.getText();
// TextFieldから取得した文字列をLabelにセット
public void initialize(URL url, ResourceBundle rb) {
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class FormSample extends Application {
public void start(Stage stage) throws Exception {
stage.setTitle("Forrm Sample");
Parent root = FXMLLoader.load(getClass().getResource("Form.fxml"));
Scene scene = new Scene(root);
public static void main(String[] args) {
.text-field {
-fx-font-size: 16pt;
.button {
-fx-font-size: 16pt;
.label {
-fx-font-size: 36pt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.