Java Code Examples for javafx.scene.Node#requestFocus()

The following examples show how to use javafx.scene.Node#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: EventQueueWait.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void requestFocus(final Node c) {
    if (Platform.isFxApplicationThread()) {
        c.requestFocus();
        return;
    }
    try {
        new EventQueueWait() {
            @Override
            public void setup() {
                c.requestFocus();
            };

            @Override
            public boolean till() {
                return c.isFocused();
            }

        }.wait("Waiting for the component to receive focus", FOCUS_WAIT, FOCUS_WAIT_INTERVAL);
    } catch (Throwable t) {
        // Ignore failure. Most times the actions should work even when the
        // focus is not set.
    }
}
 
Example 2
Source File: XPathAutocompleteProvider.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void showAutocompletePopup(int insertionIndex, String input) {

        CompletionResultSource suggestionMaker = mySuggestionProvider.get();

        List<MenuItem> suggestions =
            suggestionMaker.getSortedMatches(input, 5)
                           .map(result -> {

                               Label entryLabel = new Label();
                               entryLabel.setGraphic(result.getTextFlow());
                               entryLabel.setPrefHeight(5);
                               CustomMenuItem item = new CustomMenuItem(entryLabel, true);
                               item.setUserData(result);
                               item.setOnAction(e -> applySuggestion(insertionIndex, input, result.getStringMatch()));
                               return item;
                           })
                           .collect(Collectors.toList());

        autoCompletePopup.getItems().setAll(suggestions);


        myCodeArea.getCharacterBoundsOnScreen(insertionIndex, insertionIndex + input.length())
                  .ifPresent(bounds -> autoCompletePopup.show(myCodeArea, bounds.getMinX(), bounds.getMaxY()));

        Skin<?> skin = autoCompletePopup.getSkin();
        if (skin != null) {
            Node fstItem = skin.getNode().lookup(".menu-item");
            if (fstItem != null) {
                fstItem.requestFocus();
            }
        }
    }
 
Example 3
Source File: FocusUtil.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param node Node from which to remove focus */
public static void removeFocus(Node node)
{
    // Cannot un-focus, can only focus on _other_ node.
    // --> Find the uppermost node and focus on that.
    Node parent = node.getParent();
    if (parent == null)
        return;
    while (parent.getParent() != null)
        parent = parent.getParent();
    parent.requestFocus();
}
 
Example 4
Source File: MultiSelect.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
public void focusPrevious(Node current) {
	int index = getChildren().indexOf(current);
	if (index > 0) {
		Node previous = getChildren().get(index - 1);
		previous.requestFocus();
	}
}
 
Example 5
Source File: JFXChipViewSkin.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private void ensureVisible(Node node) {
    double height = scrollPane.getContent().getBoundsInLocal().getHeight();
    double y = node.getBoundsInParent().getMaxY();
    // scrolling values range from 0 to 1
    scrollPane.setVvalue(y / height);
    // just for usability
    node.requestFocus();
}
 
Example 6
Source File: LogViewPane.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
@MustCallOnJavaFXThread
public void focusOn( File file ) {
    for ( Node item : pane.getItems() ) {
        if ( item instanceof LogViewWrapper ) {
            if ( ( ( LogViewWrapper ) item ).logView.getFile().equals( file ) ) {
                item.requestFocus();
                break;
            }
        }
    }
}
 
Example 7
Source File: StyledTextField.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Node traverse( Parent p, Node from, int dir )
{
    if ( p == null ) return null;

    List<Node> nodeList = p.getChildrenUnmodifiable();
    int len = nodeList.size();
    int neighbor = -1;
    
    if ( from != null ) while ( ++neighbor < len && nodeList.get(neighbor) != from );
    else if ( dir == 1 ) neighbor = -1;
    else neighbor = len;
    
    for ( neighbor += dir; neighbor > -1 && neighbor < len; neighbor += dir ) {

        Node target = nodeList.get( neighbor );

        if ( target instanceof Pane || target instanceof Group ) {
            target = traverse( (Parent) target, null, dir ); // down
            if ( target != null ) return target;
        }
        else if ( target.isVisible() && ! target.isDisabled() && target.isFocusTraversable() ) {
            target.requestFocus();
            return target;
        }
    }

    return traverse( p.getParent(), p, dir ); // up
}
 
Example 8
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
public void regionClicked(MouseEvent event) {
	if (!cursorButton.isSelected()) {
		// We want to drop a new region
		regionDropped(event);
		return;
	}

	// Want to select the current region
	final Node selected = (Node) event.getTarget();
	boolean tagEditorOpen = false;

	if (tagEditor.isPresent()) {
		// Close tag editor
		tagsButton.setSelected(false);
		toggleTagEditor();
		tagEditorOpen = true;
	}

	if (cursorRegion.isPresent()) {
		final Node previous = cursorRegion.get();

		// Unhighlight the old selection
		if (!previous.equals(selected)) {
			unhighlightRegion(previous);
		}
	}

	if (((TargetRegion) selected).getType() != RegionType.IMAGE)
		((Shape) selected).setStroke(TargetRegion.SELECTED_STROKE_COLOR);
	selected.requestFocus();
	toggleShapeControls(true);
	cursorRegion = Optional.of(selected);
	if (((TargetRegion) selected).getType() != RegionType.IMAGE)
		regionColorChoiceBox.getSelectionModel().select(getColorName((Color) ((Shape) selected).getFill()));

	// Re-open editor
	if (tagEditorOpen) {
		tagsButton.setSelected(true);
		toggleTagEditor();
	}
}