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

The following examples show how to use javafx.scene.control.TextField#requestFocus() . 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: CreatorEditingTableCell.java    From tcMenu with Apache License 2.0 6 votes vote down vote up
@Override
public void startEdit() {
    super.startEdit();
    createIfNeeded();
    setGraphic(editorNode);
    setText(null);
    CreatorProperty property = getTableRow().getItem();
    if(property.getValidationRules().hasChoices()) {
        ComboBox<String> comboBox = (ComboBox) editorNode;
        comboBox.getSelectionModel().select(property.getLatestValue());
        comboBox.requestFocus();
    }
    else {
        TextField textField = (TextField) editorNode;
        textField.selectAll();
        textField.requestFocus();
    }
}
 
Example 2
Source File: CellUtils.java    From ARMStrong with Mozilla Public License 2.0 6 votes vote down vote up
static <T> void startEdit(final Cell<T> cell,
                          final StringConverter<T> converter,
                          final HBox hbox,
                          final Node graphic,
                          final TextField textField) {
    if (textField != null) {
        textField.setText(getItemText(cell, converter));
    }
    cell.setText(null);

    if (graphic != null) {
        hbox.getChildren().setAll(graphic, textField);
        cell.setGraphic(hbox);
    } else {
        cell.setGraphic(textField);
    }

    textField.selectAll();

    // requesting focus so that key input can immediately go into the
    // TextField (see RT-28132)
    textField.requestFocus();
}
 
Example 3
Source File: CellUtiles.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
static <T> void startEdit(final Cell<T> cell,
                          final StringConverter<T> converter,
                          final HBox hbox,
                          final Node graphic,
                          final TextField textField) {
    textField.setText(getItemText(cell, converter));
    cell.setText(null);

    if (graphic != null) {
        hbox.getChildren().setAll(graphic, textField);
        cell.setGraphic(hbox);
    } else {
        cell.setGraphic(textField);
    }

    textField.selectAll();

    // requesting focus so that key input can immediately go into the
    // TextField (see RT-28132)
    textField.requestFocus();
}
 
Example 4
Source File: DialogBuilder.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public static DialogBuilder newJumpLineDialog() {
    DialogBuilder dialog = new DialogBuilder("", "Goto line/column ");
    dialog.setToolTip("Enter line:column");
    dialog.setKeyReleaseEvent(LINE_COLUMN_REGEX);
    TextField editor = dialog.getEditor();
    editor.setText("0:0");
    editor.selectAll();
    editor.requestFocus();
    return dialog;
}
 
Example 5
Source File: SearchableTreeView.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Textfield for the search query.
 */
private void popSearchField() {
    TextField textField = new TextField();
    textField.setPrefWidth(150);
    textField.setPromptText("Search tree");
    ControlUtil.makeTextFieldShowPromptEvenIfFocused(textField);

    Label label = new Label();
    label.getStyleClass().addAll("hint-label");
    label.setTooltip(new Tooltip("Go to next result with F3"));

    StackPane pane = new StackPane();
    pane.getStyleClass().addAll("search-popup");
    pane.getStylesheets().addAll(DesignerUtil.getCss("designer").toString());

    StackPane.setAlignment(textField, Pos.TOP_RIGHT);
    StackPane.setAlignment(label, Pos.BOTTOM_RIGHT);


    pane.getChildren().addAll(textField, label);

    Val<String> query = Val.wrap(textField.textProperty())
                           .filter(StringUtils::isNotBlank).map(String::trim)
                           .filter(it -> it.length() >= MIN_QUERY_LENGTH);

    Var<Integer> numResults = Var.newSimpleVar(0);

    Subscription subscription = bindSearchQuery(query.conditionOnShowing(pane), numResults, textField);

    label.textProperty().bind(
        numResults.map(n -> n == 0 ? "no match" : n == 1 ? "1 match" : n + " matches")
    );

    label.visibleProperty().bind(query.map(Objects::nonNull));

    Popup popup = new Popup();
    popup.getContent().addAll(pane);
    popup.setAutoHide(true);
    popup.setHideOnEscape(true);

    Bounds bounds = localToScreen(getBoundsInLocal());
    popup.show(this, bounds.getMaxX() - textField.getPrefWidth() - 1, bounds.getMinY());
    popup.setOnHidden(e -> {
        openSearchField = null;
        subscription.unsubscribe();
    }); // release resources

    // Hide popup when ENTER or ESCAPE is pressed
    EventStreams.eventsOf(popup, KeyEvent.KEY_RELEASED)
                .filter(it -> it.getCode() == KeyCode.ENTER || it.getCode() == KeyCode.ESCAPE)
                .subscribeForOne(e -> {
                    popup.hide();
                    e.consume();
                });

    textField.requestFocus();
    openSearchField = textField;
}
 
Example 6
Source File: SelectedWidgetUITracker.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Create an inline editor
 *
 *  <p>Depending on the widget's properties, it will edit
 *  the PV name or the text.
 *
 *  @param widget Widget on which to create an inline editor
 */
private void createInlineEditor(final Widget widget)
{
    // Check for an inline-editable property
    Optional<WidgetProperty<String>> check;

    // Defaulting to PV name or text property with some hard-coded exceptions.
    // Alternative if the list of hard-coded widgets grows:
    // Add Widget#getInlineEditableProperty()
    if (widget instanceof ActionButtonWidget)
        check = Optional.of(((ActionButtonWidget) widget).propText());
    else if (widget instanceof GroupWidget)
        check = Optional.of(((GroupWidget) widget).propName());
    else
        check = widget.checkProperty(CommonWidgetProperties.propPVName);
    if (! check.isPresent())
        check = widget.checkProperty(CommonWidgetProperties.propText);
    if (! check.isPresent())
        return;

    // Create text field, aligned with widget, but assert minimum size
    final MacroizedWidgetProperty<String> property = (MacroizedWidgetProperty<String>)check.get();
    inline_editor = new TextField(property.getSpecification());
    // 'Managed' text field would assume some default size,
    // but we set the exact size in here
    inline_editor.setManaged(false);
    inline_editor.setPromptText(property.getDescription()); // Not really shown since TextField will have focus
    inline_editor.setTooltip(new Tooltip(property.getDescription()));
    inline_editor.relocate(tracker.getX(), tracker.getY());
    inline_editor.resize(Math.max(100, tracker.getWidth()), Math.max(20, tracker.getHeight()));
    getChildren().add(inline_editor);

    // Add autocomplete menu if editing property PVName
    if (property.getName().equals(CommonWidgetProperties.propPVName.getName()))
        PVAutocompleteMenu.INSTANCE.attachField(inline_editor);

    // On enter or lost focus, update the property. On Escape, just close.
    final ChangeListener<? super Boolean> focused_listener = (prop, old, focused) ->
    {
        if (! focused)
        {
            if (!property.getSpecification().equals(inline_editor.getText()))
                undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText()));
            // Close when focus lost
            closeInlineEditor();
        }
    };

    inline_editor.setOnAction(event ->
    {
        undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText()));
        inline_editor.focusedProperty().removeListener(focused_listener);
        closeInlineEditor();
    });

    inline_editor.setOnKeyPressed(event ->
    {
        switch (event.getCode())
        {
        case ESCAPE:
            event.consume();
            inline_editor.focusedProperty().removeListener(focused_listener);
            closeInlineEditor();
        default:
        }
    });

    inline_editor.focusedProperty().addListener(focused_listener);

    inline_editor.selectAll();
    inline_editor.requestFocus();
}
 
Example 7
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();
    }
}