Example usage for javafx.scene.control TextField setOnKeyReleased

List of usage examples for javafx.scene.control TextField setOnKeyReleased

Introduction

In this page you can find the example usage for javafx.scene.control TextField setOnKeyReleased.

Prototype

public final void setOnKeyReleased(EventHandler<? super KeyEvent> value) 

Source Link

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());
        }//from w  w w . j  a  v a 2  s. com
    });

    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:account.management.controller.POVoucherController.java

public void addNewRow() {
    TextField sl = new TextField();
    sl.setPromptText("SL");
    sl.setPrefWidth(54);//from  w  w w  .  ja v a  2s.  c  om
    sl.setEditable(false);

    TextField desc = new TextField();
    desc.setPromptText("Description");
    desc.setPrefWidth(216);

    TextField qty = new TextField();
    qty.setPromptText("Quantity");
    qty.setPrefWidth(62);
    qty.setOnKeyReleased((e) -> {
        calculate();
    });

    TextField rate = new TextField();
    rate.setPromptText("Rate");
    rate.setPrefWidth(72);
    rate.setOnKeyReleased((e) -> {
        calculate();
    });

    TextField total = new TextField();
    total.setPromptText("Total");
    total.setPrefWidth(80);
    total.setEditable(false);

    TextField commision = new TextField();
    commision.setPromptText("Commision %");
    commision.setPrefWidth(90);
    commision.setOnKeyReleased((e) -> {
        calculate();
    });

    TextField total_commision = new TextField();
    total_commision.setPromptText("Total Commision");
    total_commision.setPrefWidth(132);
    total_commision.setEditable(false);

    TextField neat_total = new TextField();
    neat_total.setPromptText("Neat Amount");
    neat_total.setPrefWidth(115);
    neat_total.setEditable(false);

    Button delete = new Button("Delete");

    HBox row = new HBox();
    row.setSpacing(10);
    row.getChildren().addAll(sl, desc, qty, rate, total, commision, total_commision, neat_total, delete);

    delete.setOnAction((e) -> {
        this.container.getChildren().remove(row);
        calculate();
    });

    this.container.getChildren().add(row);
    calculate();

}

From source file:account.management.controller.expenseVoucherController.java

@FXML
private void onAddNewButtonClick(ActionEvent event) {

    HBox row = new HBox();
    TextField desc = new TextField();
    TextField amount = new TextField();
    Button delete = new Button("Delete");
    desc.setPrefWidth(this.desc.getPrefWidth());
    amount.setPrefWidth(this.amount.getPrefWidth());
    row.getChildren().addAll(desc, amount, delete);
    row.setSpacing(this.row.getSpacing());
    this.container.getChildren().add(row);
    calculateTotal();/*from   ww w . j av a  2 s.c o m*/
    delete.setOnAction((e) -> {
        this.container.getChildren().remove(row);
        this.add_new.setDisable(false);
        calculateTotal();
    });
    amount.setOnKeyReleased((e) -> {
        calculateTotal();
    });
    if (this.container.getChildren().size() >= 5) {
        this.add_new.setDisable(true);
        return;
    }
}

From source file:account.management.controller.inventory.InsertStockController.java

public void addRow() {

    ComboBox<Product> select_item = new ComboBox();
    select_item.setPromptText("Select Item");
    select_item.setPrefWidth(190);//ww  w.ja  v  a2  s  .  c  o  m
    select_item.setPrefHeight(25);

    new AutoCompleteComboBoxListener<>(select_item);
    select_item.setOnHiding((e) -> {
        Product a = select_item.getSelectionModel().getSelectedItem();
        select_item.setEditable(false);
        select_item.getSelectionModel().select(a);
    });
    select_item.setOnShowing((e) -> {
        select_item.setEditable(true);
    });

    TextField qty = new TextField();
    qty.setPromptText("Quantity");
    qty.setPrefWidth(97);
    qty.setPrefHeight(25);

    TextField rate = new TextField();
    rate.setPrefWidth(100);
    rate.setPrefHeight(25);

    if (this.voucher_type.getSelectionModel().getSelectedItem().equals("Purchase")) {
        rate.setPromptText("Purchase Rate");
    } else {
        rate.setPromptText("Sell Rate");
    }

    Button del = new Button("Delete");

    HBox row = new HBox();
    row.getChildren().addAll(select_item, qty, rate, del);
    row.setSpacing(10);
    row.setPadding(new Insets(0, 0, 0, 15));

    this.conatiner.getChildren().add(row);

    del.setOnAction((e) -> {
        this.conatiner.getChildren().remove(row);
        this.add_row.setDisable(false);
        calculateTotal();
    });

    select_item.getItems().addAll(this.products_list);

    select_item.setOnAction((e) -> {
        qty.setText("0");
        if (this.voucher_type.getSelectionModel().getSelectedItem().equals("Purchase")) {
            rate.setText(String.valueOf(select_item.getSelectionModel().getSelectedItem().getLast_p_rate()));
        } else {
            rate.setText(String.valueOf(select_item.getSelectionModel().getSelectedItem().getLast_s_rate()));
        }
        calculateTotal();
    });

    qty.setOnKeyReleased((e) -> {
        calculateTotal();
    });
    rate.setOnKeyReleased((e) -> {
        calculateTotal();
    });

    if (this.conatiner.getChildren().size() >= 8) {
        this.add_row.setDisable(true);
        return;
    }

}

From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java

protected TextField createValueEditor(ChartRow chartRow, int rowNum, int column) {
    TextField editor = new TextField();
    valueEditors.put(rowNum, column, editor);
    validationRegistry.registerValidator(editor, new DoubleValidator());
    dataContainer.add(editor, column + COLUMN_OFFSET, rowNum + ROW_OFFSET);

    editor.focusedProperty().addListener(getEditorFocusListener(rowNum, editor));

    editor.textProperty().addListener((p, o, n) -> {
        editor.setUserData(true);//  ww w. j a v a2s. c  o m
    });

    BiFunction<Integer, Integer, TextField> nextTextField = (row, col) -> valueEditors.row(row).get(col);
    BiConsumer<Integer, Integer> clipBoardHandler = (row, col) -> {
        String string = Clipboard.getSystemClipboard().getString();
        if (StringUtils.containsWhitespace(string)) {
            List<String> datas = Arrays.asList(StringUtils.split(string));
            int missingRows = (row + datas.size()) - rows.size();
            if (missingRows > 0) {
                for (int i = 0; i < missingRows; i++) {
                    rows.add(new ChartRow());
                }
            }
            for (int i = row; i < row + datas.size(); i++) {
                ChartRow currentChartRow = rows.get(i);
                String data = datas.get(i - row);
                currentChartRow.setValue(column, data);
            }
        }
    };
    editor.setOnKeyReleased(getInputKeyHandler(rowNum, column, nextTextField, clipBoardHandler));
    return editor;
}

From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java

private TextField createCategoryEditor(ChartRow chartRow, int rowNum) {
    TextField categoryEditor = new TextField();
    categoryEditor.textProperty().bindBidirectional(chartRow.getCategory());

    categoryEditor.focusedProperty().addListener(getEditorFocusListener(rowNum, categoryEditor));

    categoryEditor.textProperty().addListener((p, o, n) -> {
        categoryEditor.setUserData(true);
    });// ww  w  .  ja v a2 s. c  o m
    BiFunction<Integer, Integer, TextField> nextCategoryField = (row, column) -> {
        if (categoryEditors.size() > row) {
            return categoryEditors.get(row);
        } else {
            return null;
        }
    };
    BiConsumer<Integer, Integer> clipBoardHandler = (row, col) -> {
        String string = Clipboard.getSystemClipboard().getString();
        if (StringUtils.containsWhitespace(string)) {
            List<String> datas = Arrays.asList(StringUtils.split(string, "\n"));
            int missingRows = (row + datas.size()) - rows.size();
            if (missingRows > 0) {
                for (int i = 0; i < missingRows; i++) {
                    rows.add(new ChartRow());
                }
            }
            for (int i = row; i < row + datas.size(); i++) {
                ChartRow currentChartRow = rows.get(i);
                String data = datas.get(i - row);
                currentChartRow.setCategory(data);
            }
        }
    };
    categoryEditor.setOnKeyReleased(getInputKeyHandler(rowNum, -1, nextCategoryField, clipBoardHandler));

    validationRegistry.registerValidator(categoryEditor, (control, value) -> {
        if (value != null) {
            Set<String> values = categoryEditors.stream()//
                    .filter(e -> e != categoryEditor)//
                    .map(e -> e.textProperty().getValueSafe())//
                    .filter(v -> !v.isEmpty())//
                    .collect(Collectors.toSet());
            if (values.contains(value)) {
                ValidationMessage message = new ValidationMessage("validation.noDuplicates", control, value);
                return ValidationResult.fromMessages(message);
            }
        }
        return null;
    });
    categoryEditors.add(categoryEditor);
    return categoryEditor;
}

From source file:com.playonlinux.javafx.mainwindow.console.ConsoleTab.java

public ConsoleTab(CommandLineInterpreterFactory commandLineInterpreterFactory) {
    final VBox content = new VBox();

    commandInterpreter = commandLineInterpreterFactory.createInstance();

    this.setText(translate("Console"));
    this.setContent(content);

    final TextField command = new TextField();
    command.getStyleClass().add("consoleCommandType");
    final TextFlow console = new TextFlow();
    final ScrollPane consolePane = new ScrollPane(console);
    content.getStyleClass().add("rightPane");

    consolePane.getStyleClass().add("console");
    consolePane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    content.getChildren().addAll(consolePane, command);

    command.requestFocus();/*from www .  j av a 2  s  .  c  om*/

    command.setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.ENTER) {
            final String commandToSend = command.getText();
            final int cursorPosition = command.getCaretPosition();
            command.setDisable(true);
            commandHistory.add(new CommandHistory.Item(commandToSend, cursorPosition));
            Text commandText = new Text(nextSymbol + commandToSend + "\n");
            commandText.getStyleClass().add("commandText");
            console.getChildren().add(commandText);
            command.setText("");

            if (commandInterpreter.sendLine(commandToSend, message -> {
                Platform.runLater(() -> {
                    if (!StringUtils.isBlank(message)) {
                        Text resultText = new Text(message);
                        resultText.getStyleClass().add("resultText");
                        console.getChildren().add(resultText);
                    }
                    command.setDisable(false);
                    command.requestFocus();
                    consolePane.setVvalue(consolePane.getVmax());
                });
            })) {
                nextSymbol = NOT_INSIDE_BLOCK;
            } else {
                nextSymbol = INSIDE_BLOCK;
            }
        }
    });

    command.setOnKeyReleased(event -> {
        if (event.getCode() == KeyCode.UP) {
            CommandHistory.Item historyItem = commandHistory.up();
            command.setText(historyItem.getCommand());
            command.positionCaret(historyItem.getCursorPosition());
        } else if (event.getCode() == KeyCode.DOWN) {
            CommandHistory.Item historyItem = commandHistory.down();
            command.setText(historyItem.getCommand());
            command.positionCaret(historyItem.getCursorPosition());
        }
    });

    this.setOnCloseRequest(event -> commandInterpreter.close());
}