/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ package textfieldevents; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.input.InputMethodEvent; import javafx.scene.layout.FlowPane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; /** * * @author asakharu */ public class TextFieldEvents extends Application { @Override public void start(Stage primaryStage) { TextField tf = new TextField(); Button b = new Button("Buttin"); // tf.setOnAction(new EventHandler() { // @Override // public void handle(ActionEvent event) { // System.out.println("Action performed"); // } // }); tf.addEventHandler(ActionEvent.ACTION, new EventHandler() { @Override public void handle(ActionEvent event) { System.out.println("Action performed"); } }); tf.setOnInputMethodTextChanged(new EventHandler() { @Override public void handle(InputMethodEvent t) { System.out.println("Text changed"); } }); FlowPane root = new FlowPane(Orientation.HORIZONTAL); root.getChildren().addAll(tf, b); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } /** * The main() method is ignored in correctly deployed JavaFX application. * main() serves only as fallback in case the application can not be * launched through deployment artifacts, e.g., in IDEs with limited FX * support. NetBeans ignores main(). * * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }