Java Code Examples for javafx.scene.control.TextField#setOnKeyReleased()

The following examples show how to use javafx.scene.control.TextField#setOnKeyReleased() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellUtils.java    From ARMStrong with Mozilla Public License 2.0 6 votes vote down vote up
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) {
    final TextField textField = new TextField(getItemText(cell, converter));

    // Use onAction here rather than onKeyReleased (with check for Enter),
    // as otherwise we encounter RT-34685
    textField.setOnAction(event -> {
        if (converter == null) {
            throw new IllegalStateException(
                    "Attempting to convert text input into Object, but provided "
                            + "StringConverter is null. Be sure to set a StringConverter "
                            + "in your cell factory.");
        }
        cell.commitEdit(converter.fromString(textField.getText()));
        event.consume();
    });
    textField.setOnKeyReleased(t -> {
        if (t.getCode() == KeyCode.ESCAPE) {
            cell.cancelEdit();
            t.consume();
        }
    });
    return textField;
}
 
Example 2
Source File: EditableTreeCellFactory.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
private void createTextField() {
	textField = new TextField(getString());
	textField.setOnKeyReleased(new EventHandler<KeyEvent>() {

		@Override
		public void handle(KeyEvent t) {
			if (t.getCode() == KeyCode.ENTER) {
				commitEdit(getItem());
			} else if (t.getCode() == KeyCode.ESCAPE) {
				cancelEdit();
			}
		}
	});
	textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
		@Override
		public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean focused) {
			if (!focused) {
				cancelEdit();
			}
		}
	});

}
 
Example 3
Source File: StringPropertyControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void createComponents(@NotNull HBox container) {
    super.createComponents(container);

    valueField = new TextField();
    valueField.setOnKeyReleased(this::updateValue);
    valueField.prefWidthProperty()
        .bind(widthProperty().multiply(CONTROL_WIDTH_PERCENT));

    FxControlUtils.onFocusChange(valueField, this::applyOnLostFocus);
    FxUtils.addClass(valueField,
            CssClasses.PROPERTY_CONTROL_COMBO_BOX);

    FxUtils.addChild(container, valueField);
}
 
Example 4
Source File: CellUtiles.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) {
    final TextField textField = new TextField(getItemText(cell, converter));

    // Use onAction here rather than onKeyReleased (with check for Enter),
    // as otherwise we encounter RT-34685
    textField.setOnAction(event -> {
        if (converter == null) {
            throw new IllegalStateException(
                    "Attempting to convert text input into Object, but provided "
                            + "StringConverter is null. Be sure to set a StringConverter "
                            + "in your cell factory.");
        }
        cell.commitEdit(converter.fromString(textField.getText()));
        event.consume();
    });
    textField.setOnKeyReleased(t -> {
        if (t.getCode() == KeyCode.ESCAPE) {
            cell.cancelEdit();
            t.consume();
        }
    });
    return textField;
}
 
Example 5
Source File: SmartTextFieldListCell.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private TextField getEditingGraphic(T t) {
    Var<String> stringVar = extractEditable(t);
    final TextField textField = new TextField(stringVar.getValue());

    textField.setPromptText(getPrompt());
    ControlUtil.makeTextFieldShowPromptEvenIfFocused(textField);

    // Use onAction here rather than onKeyReleased (with check for Enter),
    // as otherwise we encounter RT-34685
    textField.setOnAction(event -> {
        stringVar.setValue(textField.getText());
        commitEdit(t);
        event.consume();
    });
    textField.setOnKeyReleased(ke -> {
        if (ke.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
            ke.consume();
        }
    });
    return textField;
}
 
Example 6
Source File: ChoiceBoxTableViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.setOnKeyReleased(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                commitEdit(textField.getText());
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            }
        }
    });
}
 
Example 7
Source File: EventDetectionUI.java    From SONDY with GNU General Public License v3.0 5 votes vote down vote up
public final void detectedEventsUI(){
    // Detected events
    HBox detectedEventsBOTH = new HBox(0);
    initializeEventTable();
    initializeFrequencyChart();
    VBox detectedEventsRIGHT = new VBox(3);
    filterEventsField = new TextField();
    filterEventsField.setPromptText("Filter events");
    UIUtils.setSize(filterEventsField, Main.columnWidthRIGHT, 24);
    final EventHandler<KeyEvent> enterPressed =
        new EventHandler<KeyEvent>() {
            @Override
            public void handle(final KeyEvent keyEvent) {
                if(keyEvent.getCode()==KeyCode.ENTER){
                    eventTable.getItems().clear();
                    selectedMethod.events.filterList(filterEventsField.getText());
                    eventTable.setItems(selectedMethod.events.observableList);
                }
            }
        };
    filterEventsField.setOnKeyReleased(enterPressed);
    detectedEventsRIGHT.getChildren().addAll(filterEventsField,eventTable,createTimelineButton());
    detectedEventsBOTH.getChildren().addAll(frequencyChart,detectedEventsRIGHT);
    grid.add(detectedEventsBOTH,0,5);
    rectangleSelection = new Rectangle(0,240);
    rectangleSelection.setOpacity(0.22);
    rectangleSelection.setTranslateY(-28);
    grid.add(rectangleSelection,0,5);
}
 
Example 8
Source File: StringBasedArrayPropertyControl.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void createComponents(@NotNull HBox container) {
    super.createComponents(container);

    valueField = new TextField();
    valueField.setOnKeyReleased(this::updateValue);
    valueField.prefWidthProperty()
            .bind(widthProperty().multiply(CONTROL_WIDTH_PERCENT));

    FxUtils.addClass(valueField,
            CssClasses.PROPERTY_CONTROL_COMBO_BOX);

    FxUtils.addChild(container, valueField);
}
 
Example 9
Source File: LabelSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setOnKeyReleased((KeyEvent t) -> {
        if (t.getCode() == KeyCode.ENTER) {
            commitEdit(textField.getText());
        } else if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
        }
    });

}
 
Example 10
Source File: ComboBoxTableViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.setOnKeyReleased(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                commitEdit(textField.getText());
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            }
        }
    });
}
 
Example 11
Source File: TreeViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setOnKeyReleased((KeyEvent t) -> {
        if (t.getCode() == KeyCode.ENTER) {
            commitEdit(textField.getText());
        } else if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
        }
    });

}
 
Example 12
Source File: TableCellFactorySample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.setOnKeyReleased(new EventHandler<KeyEvent>() {                
        @Override public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                commitEdit(textField.getText());
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            }
        }
    });
}
 
Example 13
Source File: ResourceView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setOnKeyReleased(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                Resource value = getTreeItem().getValue();
                File file = new File(((FolderResource) value.getParent()).getFilePath().toFile(), textField.getText());
                if (file.exists()) {
                    FXUIUtils.showMessageDialog(null, "File " + file.getName() + " already exists", null, AlertType.ERROR);
                    cancelEdit();
                    return;
                }
                Resource renamed = value.rename(textField.getText());
                if (renamed != null) {
                    commitEdit(renamed);
                    Resource parent = (Resource) value.getParent();
                    if (parent != null) {
                        int index = parent.getChildren().indexOf(value);
                        parent.getChildren().remove(index);
                        parent.getChildren().add(index, renamed);
                    }
                } else {
                    cancelEdit();
                }
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            }
        }
    });
}
 
Example 14
Source File: TableCellFactorySample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.setOnKeyReleased(new EventHandler<KeyEvent>() {                
        @Override public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                commitEdit(textField.getText());
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            }
        }
    });
}
 
Example 15
Source File: PVTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void startEdit()
{
    super.startEdit();
    if (! isEditing())
        return;

    setText(null);

    final TableItemProxy proxy = getTableView().getItems().get(getIndex());
    final VType value = proxy.getItem().getValue();
    if (value instanceof VEnum)
    {
        // Use combo for Enum-valued data
        final VEnum enumerated = (VEnum) value;
        final ComboBox<String> combo = new ComboBox<>();
        combo.getItems().addAll(enumerated.getDisplay().getChoices());
        combo.getSelectionModel().select(enumerated.getIndex());

        combo.setOnAction(event ->
        {
            // Need to write String, using the enum index
            commitEdit(Integer.toString(combo.getSelectionModel().getSelectedIndex()));
            event.consume();
        });
        combo.setOnKeyReleased(event ->
        {
            if (event.getCode() == KeyCode.ESCAPE)
            {
                cancelEdit();
                event.consume();
            }
        });
        setGraphic(combo);
        Platform.runLater(() -> combo.requestFocus());
        Platform.runLater(() -> combo.show());
    }
    else
    {
        final TextField text_field = new TextField(getItem());
        text_field.setOnAction(event ->
        {
            commitEdit(text_field.getText());
            event.consume();
        });
        text_field.setOnKeyReleased(event ->
        {
            if (event.getCode() == KeyCode.ESCAPE)
            {
                cancelEdit();
                event.consume();
            }
        });
        setGraphic(text_field);
        text_field.selectAll();
        text_field.requestFocus();
    }
}
 
Example 16
Source File: UserBalloon.java    From DeskChan with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected UserBalloon() {
    super();
    setId("user-balloon");
    instance = this;

    TextField label = new TextField("");
    label.setFont(defaultFont);
    if (defaultFont != null) {
        label.setFont(defaultFont);
    } else {
        label.setFont(LocalFont.defaultFont);
    }

    Button infoButton = new Button(Main.getString("?"));

    HBox textLine = new HBox(label, infoButton);
    content = label;

    Button sendButton = new Button(Main.getString("send"));
    Button closeButton = new Button(Main.getString("close"));

    HBox buttons = new HBox(sendButton, closeButton);
    buttons.setAlignment(Pos.CENTER);

    bubblePane = sprite;
    sprite.setSpriteContent(new VBox(textLine, buttons));
    getChildren().add(bubblePane);

    label.setPrefWidth(bubblePane.getContentWidth());

    setBalloonScaleFactor(Main.getProperties().getFloat("balloon.scale_factor", 100));
    setBalloonOpacity(Main.getProperties().getFloat("balloon.opacity", 100));

    label.setOnKeyReleased(event -> {
        if (event.getCode() == KeyCode.ENTER) sendPhrase();
    });

    sendButton.setOnAction(event -> {
        sendPhrase();
    });

    closeButton.setOnAction(event -> {
        close();
    });

    infoButton.setOnAction(event -> {
        Main.getPluginProxy().sendMessage("DeskChan:commands-list", null);
    });

    setOnMousePressed(event -> {
        startDrag(event);
    });

    dialog = new BalloonDialog(this);
}
 
Example 17
Source File: WebPanel.java    From Quelea with GNU General Public License v3.0 4 votes vote down vote up
private void setupNavigationBarContent() {
    back = new Button("", getButtonImageView("file:icons/arrow-back.png"));
    back.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.back();
        }
    });
    forward = new Button("", getButtonImageView("file:icons/arrow-forward.png"));
    forward.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.forward();
        }
    });
    reload = new Button("", getButtonImageView("file:icons/reload.png"));
    reload.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.reload();
        }
    });
    url = new TextField();
    url.setPrefHeight(32);
    url.setMaxHeight(32);
    url.setStyle(""
            + "-fx-font-size: 14px;"
            + "-fx-font-weight: bold;"
            + "-fx-font-family: fantasy;");
    url.setTooltip(new Tooltip("Change URL"));
    url.setOnKeyReleased(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) {
            if (wd != null) {
                wd.setUrl(url.getText());
            }
        }
    });
    go = new Button("", getButtonImageView("file:icons/send.png"));
    go.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.setUrl(url.getText());
        }
    });
    plus = new Button("", getButtonImageView("file:icons/zoom-in.png"));
    plus.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.zoom(true);
        }
    });
    minus = new Button("", getButtonImageView("file:icons/zoom-out.png"));
    minus.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.zoom(false);
        }
    });
}