List of usage examples for javafx.scene.control CustomMenuItem CustomMenuItem
public CustomMenuItem(Node node, boolean hideOnClick)
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())); }