Example usage for javafx.scene.control CustomMenuItem CustomMenuItem

List of usage examples for javafx.scene.control CustomMenuItem CustomMenuItem

Introduction

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

Prototype

public CustomMenuItem(Node node, boolean hideOnClick) 

Source Link

Document

Constructs a CustomMenuItem and sets the content to the node specified.

Usage

From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java

private void autoComplete(int slashPosition, String input, ContextMenu autoCompletePopup) {

    XPathSuggestions xPathSuggestions = new XPathSuggestions(parent.getLanguageVersion().getLanguage());
    List<String> suggestions = xPathSuggestions.getXPathSuggestions(input.trim());

    List<CustomMenuItem> resultToDisplay = new ArrayList<>();
    if (!suggestions.isEmpty()) {

        for (int i = 0; i < suggestions.size() && i < 5; i++) {
            final String searchResult = suggestions.get(i);

            Label entryLabel = new Label();
            entryLabel.setGraphic(highlightXPathSuggestion(suggestions.get(i), input));
            entryLabel.setPrefHeight(5);
            CustomMenuItem item = new CustomMenuItem(entryLabel, true);
            resultToDisplay.add(item);/*w  w  w  . j  ava  2 s. c o m*/

            item.setOnAction(e -> {
                xpathExpressionArea.replaceText(slashPosition, slashPosition + input.length(), searchResult);
                autoCompletePopup.hide();
            });
        }
    }
    autoCompletePopup.getItems().setAll(resultToDisplay);

    xpathExpressionArea.getCharacterBoundsOnScreen(slashPosition, slashPosition + input.length()).ifPresent(
            bounds -> autoCompletePopup.show(xpathExpressionArea, bounds.getMinX(), bounds.getMaxY()));
}