Java Code Examples for javafx.scene.input.KeyCode#TAB

The following examples show how to use javafx.scene.input.KeyCode#TAB . 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: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void handleKey(final KeyEvent event)
{
    if (event.getCode() == KeyCode.TAB)
    {
        // Save the current text field content, since lost focus would otherwise restore previous value
        commitEdit(getConverter().fromString(editor.getText()));

        // Edit next/prev column in same row
        final ObservableList<TableColumn<List<ObservableCellValue>, ?>> columns = getTableView().getColumns();
        final int col = columns.indexOf(getTableColumn());
        final int next = event.isShiftDown()
                       ? (col + columns.size() - 1) % columns.size()
                       : (col + 1) % columns.size();
        editCell(getIndex(), columns.get(next));
        event.consume();
    }
}
 
Example 2
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void handleKey(final KeyEvent event)
{
    if (event.getCode() == KeyCode.TAB)
    {
        // Edit next/prev column in same row
        final ObservableList<TableColumn<List<ObservableCellValue>, ?>> columns = getTableView().getColumns();
        final int col = columns.indexOf(getTableColumn());
        final int next = event.isShiftDown()
                       ? (col + columns.size() - 1) % columns.size()
                       : (col + 1) % columns.size();
        editCell(getIndex(), columns.get(next));
        event.consume();
    }
    else if (event.getCode() == KeyCode.ENTER)
    {
        // Consume 'enter' and move to next row. Space can be used to toggle (or mouse click)
        event.consume();
        editCell(getIndex() + 1, getTableColumn());
    }
}
 
Example 3
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void handleKey(final KeyEvent event)
{
    if (event.getCode() == KeyCode.TAB)
    {
        // Commit value from combo's text field into combo's value...
        combo.commitValue();
        // .. and use that for the cell
        commitEdit(combo.getValue());

        // Edit next/prev column in same row
        final ObservableList<TableColumn<List<ObservableCellValue>, ?>> columns = getTableView().getColumns();
        final int col = columns.indexOf(getTableColumn());
        final int next = event.isShiftDown()
                       ? (col + columns.size() - 1) % columns.size()
                       : (col + 1) % columns.size();
        editCell(getIndex(), columns.get(next));
        event.consume();
    }
}
 
Example 4
Source File: GenericEditableTreeTableCell.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private void createEditorNode() {
    EventHandler<KeyEvent> keyEventsHandler = t -> {
        if (t.getCode() == KeyCode.ENTER) {
            commitHelper(false);
        } else if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
        } else if (t.getCode() == KeyCode.TAB) {
            commitHelper(false);
            editNext(!t.isShiftDown());
        }
    };

    ChangeListener<Boolean> focusChangeListener = (observable, oldValue, newValue) -> {
        //This focus listener fires at the end of cell editing when focus is lost
        //and when enter is pressed (because that causes the text field to lose focus).
        //The problem is that if enter is pressed then cancelEdit is called before this
        //listener runs and therefore the text field has been cleaned up. If the
        //text field is null we don't commit the edit. This has the useful side effect
        //of stopping the double commit.
        if (editorNode != null && !newValue) {
            commitHelper(true);
        }
    };
    editorNode = builder.createNode(getValue(), keyEventsHandler, focusChangeListener);
}
 
Example 5
Source File: GenericEditableTableCell.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private void createEditorNode() {
    EventHandler<KeyEvent> keyEventsHandler = t -> {
        if (t.getCode() == KeyCode.ENTER) {
            commitHelper(false);
        } else if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
        } else if (t.getCode() == KeyCode.TAB) {
            commitHelper(false);
            editNext(!t.isShiftDown());
        }
    };

    ChangeListener<Boolean> focusChangeListener = (observable, oldValue, newValue) -> {
        //This focus listener fires at the end of cell editing when focus is lost
        //and when enter is pressed (because that causes the text field to lose focus).
        //The problem is that if enter is pressed then cancelEdit is called before this
        //listener runs and therefore the text field has been cleaned up. If the
        //text field is null we don't commit the edit. This has the useful side effect
        //of stopping the double commit.
        if (editorNode != null && !newValue) {
            commitHelper(true);
        }
    };
    editorNode = builder.createNode(getValue(), keyEventsHandler, focusChangeListener);
}
 
Example 6
Source File: CollegeSelectionController.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
@FXML
public void keyTriggerMbPrefCollege(KeyEvent evt) {

    if( evt.getCode() == KeyCode.ALT || evt.getCode() == KeyCode.TAB ) {
        return;
    }

    triggerMbPrefCollege();
}
 
Example 7
Source File: AutoCompleteComboBoxListener.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
@Override
public void handle(KeyEvent event) {

    if(event.getCode() == KeyCode.UP) {
        caretPos = -1;
        moveCaret(comboBox.getEditor().getText().length());
        return;
    } else if(event.getCode() == KeyCode.DOWN) {
        if(!comboBox.isShowing()) {
            comboBox.show();
        }
        caretPos = -1;
        moveCaret(comboBox.getEditor().getText().length());
        return;
    } else if(event.getCode() == KeyCode.BACK_SPACE) {
        moveCaretToPos = true;
        caretPos = comboBox.getEditor().getCaretPosition();
    } else if(event.getCode() == KeyCode.DELETE) {
        moveCaretToPos = true;
        caretPos = comboBox.getEditor().getCaretPosition();
    }

    if(event.getCharacter().matches("[a-z]"))
        comboBox.setValue(
                (T) String.valueOf(comboBox.getValue()).toUpperCase()
        );

    if (event.getCode() == KeyCode.RIGHT || event.getCode() == KeyCode.LEFT
            || event.isControlDown() || event.getCode() == KeyCode.HOME
            || event.getCode() == KeyCode.END || event.getCode() == KeyCode.TAB) {
        return;
    }

    //if(comboBox.getItems().isEmpty()) comboBox.getItems().addAll(data);
    
   ObservableList<T> list = FXCollections.observableArrayList();
    for (T aData : data) {
        if(sc.toString(aData).toLowerCase().contains
                    (AutoCompleteComboBoxListener.this.comboBox
                    .getEditor().getText().toLowerCase())
                ){
            list.add(aData);
        }
        /*
        if (String.valueOf(aData).toLowerCase().startsWith(
                AutoCompleteComboBoxListener.this.comboBox
                        .getEditor().getText().toLowerCase())) {
            list.add(aData);
        }*/
    }
    String t = comboBox.getEditor().getText();
    comboBox.getItems().clear();
    comboBox.getItems().addAll(list);
    comboBox.getEditor().setText(t);
    if(!moveCaretToPos) {
        caretPos = -1;
    }
    moveCaret(t.length());
    if(!list.isEmpty()) {
        comboBox.show();
    }
}
 
Example 8
Source File: OSFXUtils.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static String keyEventGetKeyText(KeyCode keycode) {
    if (keycode == KeyCode.TAB) {
        return "Tab";
    }
    if (keycode == KeyCode.CONTROL) {
        return "Ctrl";
    }
    if (keycode == KeyCode.ALT) {
        return "Alt";
    }
    if (keycode == KeyCode.SHIFT) {
        return "Shift";
    }
    if (keycode == KeyCode.META) {
        return "Meta";
    }
    if (keycode == KeyCode.SPACE) {
        return "Space";
    }
    if (keycode == KeyCode.BACK_SPACE) {
        return "Backspace";
    }
    if (keycode == KeyCode.HOME) {
        return "Home";
    }
    if (keycode == KeyCode.END) {
        return "End";
    }
    if (keycode == KeyCode.DELETE) {
        return "Delete";
    }
    if (keycode == KeyCode.PAGE_UP) {
        return "Pageup";
    }
    if (keycode == KeyCode.PAGE_DOWN) {
        return "Pagedown";
    }
    if (keycode == KeyCode.UP) {
        return "Up";
    }
    if (keycode == KeyCode.DOWN) {
        return "Down";
    }
    if (keycode == KeyCode.LEFT) {
        return "Left";
    }
    if (keycode == KeyCode.RIGHT) {
        return "Right";
    }
    if (keycode == KeyCode.ENTER) {
        return "Enter";
    }
    return keycode.getName();
}
 
Example 9
Source File: JavaFxRecorderHook.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static String keyEventGetKeyText(KeyCode keyCode) {
    if (keyCode == KeyCode.TAB) {
        return "Tab";
    }
    if (keyCode == KeyCode.CONTROL) {
        return "Ctrl";
    }
    if (keyCode == KeyCode.ALT) {
        return "Alt";
    }
    if (keyCode == KeyCode.SHIFT) {
        return "Shift";
    }
    if (keyCode == KeyCode.META) {
        return "Meta";
    }
    if (keyCode == KeyCode.SPACE) {
        return "Space";
    }
    if (keyCode == KeyCode.BACK_SPACE) {
        return "Backspace";
    }
    if (keyCode == KeyCode.HOME) {
        return "Home";
    }
    if (keyCode == KeyCode.END) {
        return "End";
    }
    if (keyCode == KeyCode.DELETE) {
        return "Delete";
    }
    if (keyCode == KeyCode.PAGE_UP) {
        return "Pageup";
    }
    if (keyCode == KeyCode.PAGE_DOWN) {
        return "Pagedown";
    }
    if (keyCode == KeyCode.UP) {
        return "Up";
    }
    if (keyCode == KeyCode.DOWN) {
        return "Down";
    }
    if (keyCode == KeyCode.LEFT) {
        return "Left";
    }
    if (keyCode == KeyCode.RIGHT) {
        return "Right";
    }
    if (keyCode == KeyCode.ENTER) {
        return "Enter";
    }
    return keyCode.getName();
}