@Override public void start(final Stage stage) throws IOException { VBox optionPane = new VBox(10); MenuBar menuBar = new MenuBar(); menuBar.getMenus().addAll(new Menu("School"), new Menu("Social"), new Menu("Network")); root.getChildren().addAll(new TreeItem<>("Layout"), new TreeItem<>("is not"), new TreeItem<>("easy")); TreeView<String> notes = new TreeView<>(root); optionPane.getChildren().addAll(menuBar, new Label("Kaiser Notes"), notes); optionPane.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); VBox editorBox = new VBox(10); TextField textField = new TextField(); editorBox.getChildren().addAll(textField, editor); editorBox.setStyle("-fx-background-color: mistyrose; -fx-padding: 10;"); textField.setMinHeight(Control.USE_PREF_SIZE); // stop the textfield from getting squashed when the scene is sized small. editorBox.setMinSize(0, 0); // stops the editor from overflowing it's bounds in a BorderPane. layout.setLeft(optionPane); layout.setCenter(editorBox); stage.setScene(new Scene(layout)); stage.show();
TextField textField = new TextField(); textField.textProperty().addListener((observable, oldValue, newValue) -> { System.out.println("textfield changed from " + oldValue + " to " + newValue); });
TextField x = new TextField("text"); x.setRequired(true);
textField = new TextField(); hbox.setStyle("-fx-background-color: #336699"); hbox.setAlignment(Pos.BOTTOM_CENTER); HBox.setMargin(b2, new Insets(10,0,10,0)); HBox.setMargin(b1, new Insets(10,0,10,0)); hbox.getChildren().addAll(b1,b2); borderPane.setTop(hbox); borderPane.setCenter(table); BorderPane.setAlignment(table, Pos.CENTER); BorderPane.setMargin(table, new Insets(25));
primaryStage.setTitle( "Hello World!" ); final List<Integer> list = new ArrayList<>(); Button btn = new Button(); btn.setText( "Say 'Hello World'" ); btn.setOnAction( new EventHandler<ActionEvent>() BooleanBinding bb = Bindings.createBooleanBinding( () -> oblist.contains( 1 ), oblist ); TextField txt = new TextField(); txt.textProperty().bind( bb.asString() ); VBox root = new VBox(); root.getChildren().addAll( btn, txt ); primaryStage.setScene( scene ); primaryStage.show();
TextField tf = new TextField(); Label label = new Label("Your Name: "); Button submit = new Button("submit"); GridPane root = new GridPane(); label.setLabelFor(tf); root.setPadding(new Insets(10)); root.setVgap(5); root.setHgap(5); submit.setOnAction((ActionEvent event) -> { if (!done.getAndSet(true)) { System.out.println("Your name is " + tf.getText()); primaryStage.setScene(scene); primaryStage.show();
public void start(Stage primaryStage) { HBox hbox = new HBox(10); TextField field = new TextField(); HBox.setHgrow(field, Priority.ALWAYS); hbox.setAlignment(Pos.BASELINE_LEFT); hbox.getChildren().addAll( new Label("Search:"), field, new Button("Go") ); hbox.setPadding(new Insets(10)); Scene scene = new Scene(hbox, 600, 250, Color.WHITE); primaryStage.setScene(scene); primaryStage.show(); }
while(!inputFile.exists()) { window = new Stage(); window.initModality(Modality.APPLICATION_MODAL); window.setTitle("File was not found."); window.setMinWidth(250); window.setMaxHeight(100); //form TextField fileInput = new TextField(); Button inputButton = new Button("Upload File"); inputButton.setOnAction(e -> { inputFile = new File(fileInput.getText()); window.close(); }); //Layout VBox layout = new VBox(10); layout.setPadding(new Insets(20, 20, 20, 20)); layout.getChildren().addAll(fileInput, inputButton); //Set scene and show in window. Scene scene = new Scene(layout, 300, 100); window.setScene(scene); window.showAndWait(); }
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TextFieldShadows extends Application { @Override public void start(final Stage stage) throws Exception { TextField standardTextField = new TextField(); TextField styledTextField = new TextField(); styledTextField.setStyle( "-fx-background-color: -fx-text-box-border, -fx-control-inner-background;" ); VBox layout = new VBox(10, standardTextField, styledTextField); layout.setPadding(new Insets(10)); stage.setScene(new Scene(layout)); stage.show(); } public static void main(String[] args) throws Exception { launch(args); } }
VBox root = new VBox(10); TextField textField = new TextField("Text Field"); Label label = new Label("Label"); root.getChildren().addAll(textField, label, text); root.setAlignment(Pos.CENTER); root.setPadding(new Insets(20)); Scene scene = new Scene(root); scene.getStylesheets().add("text-css-test.css"); primaryStage.setScene(scene); primaryStage.show();
TextField textField = new TextField("http://stackoverflow.com/questions/39898704"); Button openURLButton = new Button("Open URL"); EventHandler<ActionEvent> handler = e -> open(textField.getText()); textField.setOnAction(handler); openURLButton.setOnAction(handler); Button openFileButton = new Button("Open File..."); openFileButton.setOnAction(e -> { File file = fileChooser.showOpenDialog(primaryStage); VBox root = new VBox(5, new HBox(new Label("URL:"), textField, openURLButton), new HBox(openFileButton) ); root.setPadding(new Insets(20)); primaryStage.setScene(new Scene(root)); primaryStage.show();
stage.setTitle("Validation Demo"); BorderPane borderPane = new BorderPane(); grid.add(scenetitle, 0, 0, 2, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); final TextField userTextField = new TextField(); grid.add(userTextField, 1, 1); grid.add(pwBox, 1, 2); btn.setOnAction(new EventHandler<ActionEvent>() { if (userTextField.getText().equals("")) { usernameValidator.getItems().clear(); usernameValidator.getItems().add( && !userTextField.getText().equals("")) { actiontarget.setFill(Color.GREEN); actiontarget.setText("Welcome"); userTextField.focusedProperty().addListener( new ChangeListener<Boolean>() { @Override
@Override public void start(Stage stage) { TextField textField = new TextField(); Label label = new Label(); label.textProperty().bind( Bindings.createStringBinding( () -> new StringBuilder(textField.getText()).reverse().toString(), textField.textProperty() layout.setPadding(new Insets(10)); stage.setScene(new Scene(layout)); stage.show();
public class Main extends Application { @Override public void start(Stage stage) { final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); final TextField textField = new TextField(); final Button button = new Button(); vbox.getChildren().addAll(textField, button); vbox.onKeyPressedProperty().set(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { textField.requestFocus(); } }); stage.setScene(new Scene(vbox, 300, 500)); stage.show(); } public static void main(String[] args) { launch(args); } }
@Override public void start(Stage stage) { TextField textField = new TextField(); textField.setPromptText("Enter text to be appended."); Button append = new Button("Append"); append.setDefaultButton(true); TextArea textArea = new TextArea(); textArea.setPromptText("Appended text is displayed here."); textArea.setEditable(false); append.setOnAction(event -> { textArea.setText(textArea.getText() + textField.getText() + "\n"); textField.clear(); }); VBox layout = new VBox(10); layout.getChildren().addAll( textField, append, textArea ); layout.setPadding(new Insets(10)); stage.setScene(new Scene(layout)); stage.show();
public class Demo extends Application { @Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root); stage.setScene(scene); TextField myTextField = new TextField("default"); Rectangle myRectangle = new Rectangle(); myRectangle.setHeight(30); myRectangle.setFill(Color.AQUA); myRectangle.widthProperty().bind(myTextField.widthProperty()); final VBox hb = new VBox(10); hb.setPadding(new Insets(5)); hb.getChildren().addAll(myTextField, myRectangle); scene.setRoot(hb); stage.show(); } public static void main(String[] args) { launch(args); } }
TextField textField = new TextField(); textField.setPromptText("Enter text"); textField.pseudoClassStateChanged(empty, true); textField.textProperty().addListener((obs, oldText, newText) -> { textField.pseudoClassStateChanged(empty, newText.isEmpty()); }); Button okButton = new Button("OK"); VBox root = new VBox(10, textField, okButton); root.setAlignment(Pos.CENTER); root.setPadding(new Insets(24)); primaryStage.setScene(scene); primaryStage.show();
Button button = new Button("Click Me"); TextField textField = new TextField(); button.addEventHandler(KeyEvent.KEY_PRESSED, e -> System.out.println("Key press on button")); button.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> System.out.println("Mouse press on button")); button.addEventHandler(ActionEvent.ACTION, e -> System.out.println("Action on button")); textField.addEventHandler(ActionEvent.ACTION, e -> System.out.println("Action on text field")); root.setAlignment(Pos.CENTER); root.setPadding(new Insets(24)); primaryStage.setScene( new Scene(root) ); primaryStage.show();
TextField tf1 = new TextField(); TextField tf2 = new TextField(); TextField tf3 = new TextField(); TextField tf4 = new TextField(); TextField tf5 = new TextField(); TextField tf6 = new TextField(); Button button = new Button("Submit"); button.disableProperty().bind( emptyTextFieldBinding(tf1) .or(emptyTextFieldBinding(tf2)) root.setAlignment(Pos.CENTER); root.setPadding(new Insets(10)); Scene scene = new Scene(root, 150, 400); primaryStage.setScene(scene); primaryStage.show(); return Bindings.length(textField.textProperty()).isEqualTo(0);
@Override public void start(Stage primaryStage) throws Exception{ TextField textfield = new TextField(); ListView listView = new ListView(); listView.getItems().add("One"); listView.getItems().add("Two"); listView.getItems().add("Three"); Button button = new Button("Button"); VBox root = new VBox(5, textfield, listView, button); root.addEventFilter(KeyEvent.KEY_PRESSED, event->{ if (event.getCode() == KeyCode.SPACE) { System.out.println("GOOD"); } }); root.setAlignment(Pos.CENTER); root.setPadding(new Insets(10)); primaryStage.setScene(new Scene(root, 400, 400)); primaryStage.show(); }