Example usage for javafx.scene.input KeyEvent getText

List of usage examples for javafx.scene.input KeyEvent getText

Introduction

In this page you can find the example usage for javafx.scene.input KeyEvent getText.

Prototype

public final String getText() 

Source Link

Document

A String describing the key code, such as "HOME", "F1" or "A", for key pressed and key released events.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    textBox.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            System.out.println("Key Pressed: " + ke.getText());
        }/*  w  w  w. j av  a  2 s  .c o m*/
    });

    textBox.setOnKeyReleased(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            System.out.println("Key Released: " + ke.getText());
        }
    });

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:com.hengyi.japp.print.client.controller.MdController.java

@FXML
private void autoCompleteSapMara(KeyEvent ev) {
    try {/* ww  w .jav a2s.c  o m*/
        if (KeyCode.RIGHT.equals(ev.getCode())) {
            List<SapMara> sapMaras = md.getSapT001().autoCompleteSapMara(matnrField.getText());
            sapMaraListView.setItems(observableArrayList(sapMaras));
            sapMaraListView.setVisible(true);
            sapMaraListView.getSelectionModel().selectFirst();
        } else if (KeyCode.UP.equals(ev.getCode()) || KeyCode.DOWN.equals(ev.getCode())) {
            sapMaraListView.fireEvent(new KeyEvent(null, sapMaraListView, KeyEvent.KEY_PRESSED,
                    ev.getCharacter(), ev.getText(), ev.getCode(), false, false, false, false));
        } else if (KeyCode.ENTER.equals(ev.getCode())) {
            selectSapMara(sapMaraListView.getSelectionModel().getSelectedItem());
            sapMaraListView.setVisible(false);
        }
    } catch (Exception ex) {
        Util.alertDialog(ex);
    }
}