Created
July 5, 2012 11:02
-
-
Save skrb/3052988 to your computer and use it in GitHub Desktop.
JavaFX Simple FXML-Controler Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import java.lang.*?> | |
<?import java.net.*?> | |
<?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="http://javafx.com/fxml" fx:controller="FormController"> | |
<children> | |
<HBox alignment="CENTER" prefHeight="32.0" prefWidth="320.0" spacing="20.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> | |
<children> | |
<TextField fx:id="field" prefWidth="200.0" /> | |
<Button fx:id="button" onAction="#handleAction" text="Submit" /> | |
</children> | |
</HBox> | |
<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" /> | |
</children> | |
<stylesheets> | |
<URL value="@formstyle.css" /> | |
</stylesheets> | |
</AnchorPane> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URL; | |
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 { | |
@FXML | |
private TextField field; | |
@FXML | |
private Label label; | |
@FXML | |
private void handleAction(ActionEvent event) { | |
// TextFiled から文字列を取得 | |
String text = field.getText(); | |
// TextFieldから取得した文字列をLabelにセット | |
label.setText(text); | |
} | |
@Override | |
public void initialize(URL url, ResourceBundle rb) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
@Override | |
public void start(Stage stage) throws Exception { | |
stage.setTitle("Forrm Sample"); | |
Parent root = FXMLLoader.load(getClass().getResource("Form.fxml")); | |
Scene scene = new Scene(root); | |
stage.setScene(scene); | |
stage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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