/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. */ package helloworld; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.stage.Stage; public class HelloTextFieldJc extends Application { private double fontSize = Font.getDefault().getSize(); private Insets insets = new Insets(3, 5, 3, 5); @Override public void start(Stage stage) { // We have 2 boxes, a TextField and a PasswordField. Then there are a bunch of buttons // which cycle various states of these controls, such as the font size, or trying to paste // illegal characters, etc. final TextField textField1 = new TextField("This is the first text field..."); final TextField textField2 = new TextField("This is the second text field..."); final TextField textField3 = new TextField("This is the third text field..."); // Button setIllegalCharsBtn = new Button("Set Illegal Characters"); // setIllegalCharsBtn.setOnAction(new EventHandler() { // @Override public void handle(ActionEvent event) { // textField.setText("Illegal characters here -->" + '\05' + '\07' + '\0' + "<--"); // } // }); // // Button increasePrefColumnCountBtn = new Button("Increase prefColumnCount"); // increasePrefColumnCountBtn.setOnAction(new EventHandler() { // @Override public void handle(ActionEvent event) { // textField.setPrefColumnCount(textField.getPrefColumnCount() + 5); // passwordField.setPrefColumnCount(passwordField.getPrefColumnCount() + 5); // } // }); // // Button decreasePrefColumnCountBtn = new Button("Decrease prefColumnCount"); // decreasePrefColumnCountBtn.setOnAction(new EventHandler() { // @Override public void handle(ActionEvent event) { // textField.setPrefColumnCount(textField.getPrefColumnCount() - 5); // passwordField.setPrefColumnCount(passwordField.getPrefColumnCount() - 5); // } // }); // // Button increaseFontSizeBtn = new Button("Increase Font Size"); // increaseFontSizeBtn.setOnAction(new EventHandler() { // @Override public void handle(ActionEvent event) { // fontSize += 1; // textField.setStyle("-fx-font-size: " + fontSize + "pt"); // passwordField.setStyle("-fx-font-size: " + fontSize + "pt"); // } // }); // // Button decreaseFontSizeBtn = new Button("Decrease Font Size"); // decreaseFontSizeBtn.setOnAction(new EventHandler() { // @Override public void handle(ActionEvent event) { // fontSize -= 1; // textField.setStyle("-fx-font-size: " + fontSize + "pt"); // passwordField.setStyle("-fx-font-size: " + fontSize + "pt"); // } // }); // // Button defaultBtn = new Button("Default Action"); // defaultBtn.setDefaultButton(true); // defaultBtn.setOnAction(new EventHandler() { // @Override public void handle(ActionEvent event) { // System.out.println("Default Action"); // } // }); VBox fieldBox = new VBox(5); fieldBox.setFillWidth(false); fieldBox.getChildren().addAll(textField1, textField2, textField3); // VBox buttonBox = new VBox(5); // buttonBox.getChildren().addAll( // setIllegalCharsBtn, // increasePrefColumnCountBtn, // decreasePrefColumnCountBtn, // increaseFontSizeBtn, // decreaseFontSizeBtn, // defaultBtn); HBox root = new HBox(7); root.setPadding(new Insets(11, 12, 12, 11)); root.getChildren().addAll(fieldBox); stage.setScene(new Scene(root, 800, 600)); stage.show(); } public static void main(String[] args) { launch(args); } }