javafx.scene.control.MenuItem Java Examples
The following examples show how to use
javafx.scene.control.MenuItem.
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: PhoebusApplication.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** @param entry {@link MenuEntry} * @return {@link MenuItem} */ private MenuItem createMenuItem(final MenuEntry entry) { final MenuItem item = new MenuItem(entry.getName()); final Image icon = entry.getIcon(); if (icon != null) item.setGraphic(new ImageView(icon)); item.setOnAction(event -> { try { entry.call(); } catch (Exception ex) { logger.log(Level.WARNING, "Error invoking menu " + entry.getName(), ex); } }); return item; }
Example #2
Source File: NavigationAction.java From phoebus with Eclipse Public License 1.0 | 6 votes |
private void updateUI(final DisplayNavigation navigation) { final List<DisplayInfo> displays = getDisplays(); final int N = displays.size(); if (N<=0) { image.setImage(disabled); getItems().clear(); } else { image.setImage(icon); final List<MenuItem> items = new ArrayList<>(N); for (int i=0; i<N; ++i) items.add(createNavigationItem(displays.get(N-i-1), i+1)); getItems().setAll(items); } }
Example #3
Source File: ChannelInformation.java From paintera with GNU General Public License v2.0 | 6 votes |
public Node getNode() { final TextField channels = new TextField(); channels.setEditable(false); channels.setTooltip(new Tooltip("Channel selection")); channelSelection.addListener((obs, oldv, newv) -> channels.setText(String.join(", ", IntStream.of(newv).boxed().map(Object::toString).toArray(String[]::new)))); MenuItem all = new MenuItem("_All"); all.setOnAction(e -> channelSelection.set(range())); MenuItem revert = new MenuItem("_Revert"); revert.setOnAction(e -> channelSelection.set(reverted(channelSelection.get()))); MenuItem everyNth = new MenuItem("Every _Nth"); everyNth.setOnAction(e -> everyNth(numChannels.get()).ifPresent(channelSelection::set)); final MenuButton selectionButton = new MenuButton("_Select", null, all, revert, everyNth); HBox.setHgrow(channels, Priority.ALWAYS); return new VBox( new Label("Channel Settings"), new HBox(channels, selectionButton)); }
Example #4
Source File: RFXMenuItemTest.java From marathonv5 with Apache License 2.0 | 6 votes |
@Test public void duplicateMenuPath() { List<String> path = new ArrayList<>(); Platform.runLater(() -> { Menu menuFile = new Menu("File"); MenuItem add = new MenuItem("Shuffle"); MenuItem clear = new MenuItem("Clear"); MenuItem clear1 = new MenuItem("Clear"); MenuItem clear2 = new MenuItem("Clear"); MenuItem exit = new MenuItem("Exit"); menuFile.getItems().addAll(add, clear, clear1, clear2, new SeparatorMenuItem(), exit); RFXMenuItem rfxMenuItem = new RFXMenuItem(null, null); path.add(rfxMenuItem.getSelectedMenuPath(clear2)); }); new Wait("Waiting for menu selection path") { @Override public boolean until() { return path.size() > 0; } }; AssertJUnit.assertEquals("File>>Clear(2)", path.get(0)); }
Example #5
Source File: SelectableLabel.java From constellation with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param text the label to use for the text. Styles will be copied from * this label. * @param wrapText specifies whether text wrapping is allowed in this label. * @param style the CSS style of the label. This can be null. * @param tipsPane the tooltip for the label. This can be null. * @param contextMenuItems a list of menu items to add to the context menu * of the label. This can be null. */ public SelectableLabel(final String text, boolean wrapText, String style, final TooltipPane tipsPane, final List<MenuItem> contextMenuItems) { getStyleClass().add("selectable-label"); setText(text == null ? "" : text); setWrapText(wrapText); setEditable(false); setPadding(Insets.EMPTY); setCache(true); setCacheHint(CacheHint.SPEED); setMinHeight(USE_PREF_SIZE); if (style != null) { setStyle(style); } if (tipsPane != null) { TooltipUtilities.activateTextInputControl(this, tipsPane); } this.contextMenuItems = contextMenuItems; }
Example #6
Source File: HelpBrowser.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
@Override public void load() { super.load(); Platform.runLater(new Runnable() { // this will run initFX as JavaFX-Thread @Override public void run() { webView.setContextMenuEnabled(false); contextMenu = new ContextMenu(); open = new MenuItem("Open in browser"); addActionListener(); addContextMenuListener(); contextMenu.getItems().addAll(open); } }); }
Example #7
Source File: AllFilesViewerController.java From standalone-app with Apache License 2.0 | 6 votes |
public void openOpenNewTabMenu() { if (root.getSelectionModel().getSelectedItem() != null) { Tab selectedFile = root.getSelectionModel().getSelectedItem(); ContextMenu contextMenu = new ContextMenu(); for (EditorView ev : editorController.getRegisteredEditors()) { MenuItem item = new MenuItem(ev.getDisplayName()); item.setOnAction(event -> { openNewEditor(selectedFile, ev); }); contextMenu.getItems().add(item); } contextMenu.setOnHidden(event -> { isMenuOpen = false; }); Point p = MouseInfo.getPointerInfo().getLocation(); contextMenu.show(root.getScene().getWindow(), p.x, p.y); } }
Example #8
Source File: LyricsTextArea.java From Quelea with GNU General Public License v3.0 | 6 votes |
public LyricsTextArea() { textArea = new InlineCssTextArea(); ContextMenu contextMenu = new ContextMenu(); Clipboard systemClipboard = Clipboard.getSystemClipboard(); MenuItem paste = new MenuItem(LabelGrabber.INSTANCE.getLabel("paste.label")); contextMenu.setOnShown(e -> { paste.setDisable(!systemClipboard.hasContent(DataFormat.PLAIN_TEXT)); }); paste.setOnAction(e -> { String clipboardText = systemClipboard.getString(); textArea.insertText(textArea.getCaretPosition(), clipboardText); }); contextMenu.getItems().add(paste); textArea.setContextMenu(contextMenu); textArea.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { Platform.runLater(this::refreshStyle); }); textArea.setStyle("-fx-font-family: monospace; -fx-font-size: 10pt;"); textArea.setUndoManager(UndoManagerFactory.zeroHistorySingleChangeUM(textArea.richChanges())); getChildren().add(new VirtualizedScrollPane<>(textArea)); textArea.getStyleClass().add("text-area"); }
Example #9
Source File: MenuButtonDemo.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override public void start(final Stage stage) { final MenuButton button1 = new MenuButton("Plain Button", null, new MenuItem("Item 1"), new MenuItem("Item 2")); button1.getStyleClass().add("action_button"); final MenuItem item = new MenuItem("Action Button Item"); item.getStyleClass().add("action_button_item"); final MenuButton button2 = new MenuButton("Dark Button", null, item, new MenuItem("Plain Item")); button2.setStyle(JFXUtil.shadedStyle(new WidgetColor(100, 0, 0))); button2.setTextFill(Color.YELLOW); button2.getStyleClass().add("action_button"); final HBox box = new HBox(button1, button2); final Scene scene = new Scene(box, 800, 700); // XXX Enable scenic view to debug styles // ScenicView.show(scene); JFXRepresentation.setSceneStyle(scene); stage.setScene(scene); stage.setTitle("MenuButtons"); stage.show(); }
Example #10
Source File: DemoView.java From PreferencesFX with Apache License 2.0 | 6 votes |
private void initializeParts() { menuBar = new MenuBar(); menu = new Menu("Edit"); preferencesMenuItem = new MenuItem("Preferences"); welcomeLbl = new Label(); brightnessLbl = new Label(); nightModeLbl = new Label(); scalingLbl = new Label(); screenNameLbl = new Label(); resolutionLbl = new Label(); orientationLbl = new Label(); favoritesLbl = new Label(); fontSizeLbl = new Label(); lineSpacingLbl = new Label(); favoriteNumberLbl = new Label(); englishBtn = new Button("English"); germanBtn = new Button("German"); }
Example #11
Source File: RFXMenuItem.java From marathonv5 with Apache License 2.0 | 6 votes |
private String getTagForMenu(MenuItem source) { LinkedList<MenuItem> menuItems = new LinkedList<>(); while (source != null) { menuItems.addFirst(source); source = source.getParentMenu(); } if (menuItems.getFirst() instanceof Menu) { if (menuItems.size() >= 2) { ownerNode = menuItems.get(1).getParentPopup().getOwnerNode(); return isMenuBar(ownerNode) ? "#menu" : "#contextmenu"; } } else { ownerNode = menuItems.getFirst().getParentPopup().getOwnerNode(); return "#contextmenu"; } return null; }
Example #12
Source File: CustomNavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 6 votes |
private Button buildMenuItem(MenuItem item) { Button button = new Button(); button.textProperty().bind(item.textProperty()); button.graphicProperty().bind(item.graphicProperty()); button.disableProperty().bind(item.disableProperty()); button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); button.getStyleClass().addAll(item.getStyleClass()); button.setOnAction(item.getOnAction()); // Only in cases ALWAYS and SOMETIMES: hide previously hovered button if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { button.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Button if (!isTouchUsed) { if (hoveredBtn != null) { hoveredBtn.hide(); // Hides the previously hovered Button if not null } hoveredBtn = null; // Sets it to null } }); } return button; }
Example #13
Source File: MyBoxController.java From MyBox with Apache License 2.0 | 6 votes |
@FXML private void showRecentMenu(MouseEvent event) { hideMenu(event); popMenu = new ContextMenu(); popMenu.setAutoHide(true); popMenu.getItems().addAll(getRecentMenu()); popMenu.getItems().add(new SeparatorMenuItem()); MenuItem closeMenu = new MenuItem(message("MenuClose")); closeMenu.setStyle("-fx-text-fill: #2e598a;"); closeMenu.setOnAction((ActionEvent cevent) -> { popMenu.hide(); popMenu = null; }); popMenu.getItems().add(closeMenu); showMenu(recentBox, event); view.setImage(new Image("img/RecentAccess.png")); text.setText(message("RecentAccessImageTips")); locateImage(recentBox, true); }
Example #14
Source File: TreeNode.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Fill the items actions for this node. * * @param nodeTree the node tree * @param items the items */ @FxThread public void fillContextMenu(@NotNull final NodeTree<?> nodeTree, @NotNull final ObservableList<MenuItem> items) { if (canEditName()) { items.add(new RenameNodeAction(nodeTree, this)); } if (canCopy()) { items.add(new CopyNodeAction(nodeTree, this)); } final Clipboard clipboard = Clipboard.getSystemClipboard(); final Object content = clipboard.getContent(DATA_FORMAT); if (!(content instanceof Long)) { return; } final Long objectId = (Long) content; final TreeItem<?> treeItem = UiUtils.findItem(nodeTree.getTreeView(), objectId); final TreeNode<?> treeNode = treeItem == null ? null : (TreeNode<?>) treeItem.getValue(); if (treeNode != null && canAccept(treeNode, true)) { items.add(new PasteNodeAction(nodeTree, this, treeNode)); } }
Example #15
Source File: ACEEditor.java From marathonv5 with Apache License 2.0 | 6 votes |
private void createURLLink(String pattern, String id, String icon) { MenuItem tmsMenuItem = new MenuItem(id, FXUIUtils.getIcon(icon)); if (pattern != null && pattern.length() > 0) { String url = String.format(pattern, id); tmsMenuItem.setOnAction((event) -> { try { Desktop.getDesktop().browse(new URI(url)); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } }); } else { tmsMenuItem.setDisable(true); } infoButton.getItems().add(tmsMenuItem); }
Example #16
Source File: MainLayoutController.java From javafx-TKMapEditor with GNU General Public License v3.0 | 6 votes |
private void initRecentFiles() { Config.getInstance().readConfig(); ArrayList<String> paths = Config.getInstance().getFilePaths(); for (String path : paths) { MenuItem item = new MenuItem(path); item.setOnAction(e -> { File file = new File(path); if(file.exists()){ readMapWithAlert(new File(path)); } else { AlertDialog.showAlertDialog("地图文件不存在"); mRecentMenu.getItems().remove(this); removeRecentFile(file); } }); mRecentMenu.getItems().add(item); } }
Example #17
Source File: SnapshotTable.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private ContextMenu createContextMenu(final int snapshotIndex) { MenuItem removeItem = new MenuItem("Remove"); // removeItem.setOnAction(ev -> SaveAndRestoreService.getInstance().execute("Remove Snapshot", // () -> update(controller.removeSnapshot(snapshotIndex)))); MenuItem setAsBaseItem = new MenuItem("Set As Base"); // setAsBaseItem.setOnAction(ev -> SaveAndRestoreService.getInstance().execute("Set new base Snapshot", // () -> update(controller.setAsBase(snapshotIndex)))); MenuItem moveToNewEditor = new MenuItem("Move To New Editor"); // moveToNewEditor.setOnAction(ev -> SaveAndRestoreService.getInstance().execute("Open Snapshot", // () -> update(controller.moveSnapshotToNewEditor(snapshotIndex)))); return new ContextMenu(removeItem, setAsBaseItem, new SeparatorMenuItem(), moveToNewEditor); }
Example #18
Source File: SimulationDisplay.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void createContextMenu() { final MenuItem save = new MenuItem("Save as text file", ImageCache.getImageView(ImageCache.class, "/icons/save_edit.png")); save.setOnAction(event -> save()); final ContextMenu menu = new ContextMenu(save); log.setContextMenu(menu); }
Example #19
Source File: BibleSearchPopupMenu.java From Quelea with GNU General Public License v3.0 | 5 votes |
/** * Create the bible search popup menu. */ public BibleSearchPopupMenu() { viewVerseItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("open.in.browser")); viewVerseItem.setOnAction(new EventHandler<javafx.event.ActionEvent>() { @Override public void handle(javafx.event.ActionEvent t) { trigger(); } }); getItems().add(viewVerseItem); }
Example #20
Source File: MainController.java From KorgPackage with GNU General Public License v3.0 | 5 votes |
public void addChunk(ActionEvent e) { Chunk chunk; MenuItem menuItem = (MenuItem) e.getSource(); if (menuItem.getText().equals("Header")) { chunk = new HeaderChunk(); } else if (menuItem.getText().equals("System file")) { chunk = new SystemFileChunk(Chunk.UPDATE_KERNEL); } else if (menuItem.getText().equals("Installer script")) { chunk = new InstallerScriptChunk(); } else if (menuItem.getText().equals("Directory")) { chunk = new DirectoryChunk(); } else if (menuItem.getText().equals("File")) { chunk = new FileChunk(0); } else if (menuItem.getText().equals("File system")) { chunk = new RootFSChunk(); } else { return; } Chunk c = (Chunk) chunksListView.getSelectionModel().getSelectedItem(); if (c != null) { int index = chunksListView.getSelectionModel().getSelectedIndex(); chunksListView.getItems().add(index + 1, chunk); } else { chunksListView.getItems().add(chunk); } chunksListView.getSelectionModel().clearSelection(); chunksListView.getSelectionModel().select(chunk); }
Example #21
Source File: ContextMenuTests.java From RichTextFX with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void start(Stage stage) throws Exception { super.start(stage); menu = new ContextMenu(new MenuItem("A menu item")); area.setContextMenu(menu); area.setContextMenuXOffset(offset); area.setContextMenuYOffset(offset); }
Example #22
Source File: TaChartViewer.java From TAcharting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates the context menu. * * @return The context menu. */ private ContextMenu createContextMenu() { final ContextMenu menu = new ContextMenu(); menu.setAutoHide(true); Menu export = new Menu("Export As"); MenuItem pngItem = new MenuItem("PNG..."); pngItem.setOnAction(e -> handleExportToPNG()); export.getItems().add(pngItem); MenuItem jpegItem = new MenuItem("JPEG..."); jpegItem.setOnAction(e -> handleExportToJPEG()); export.getItems().add(jpegItem); if (ExportUtils.isOrsonPDFAvailable()) { MenuItem pdfItem = new MenuItem("PDF..."); pdfItem.setOnAction(e -> handleExportToPDF()); export.getItems().add(pdfItem); } if (ExportUtils.isJFreeSVGAvailable()) { MenuItem svgItem = new MenuItem("SVG..."); svgItem.setOnAction(e -> handleExportToSVG()); export.getItems().add(svgItem); } menu.getItems().add(export); return menu; }
Example #23
Source File: PatientModule.java From WorkbenchFX with Apache License 2.0 | 5 votes |
private ToolbarItem createLanguageItem() { MenuItem de = new MenuItem("de"); de.setOnAction(event -> translator.translateToGerman()); MenuItem en = new MenuItem("en"); en.setOnAction(event -> translator.translateToEnglish()); return new ToolbarItem(new MaterialDesignIconView(MaterialDesignIcon.TRANSLATE), de, en); }
Example #24
Source File: MatchSelectionExample.java From paintera with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IOException { final List<String> filenames = Files.list(Paths.get(System.getProperty("user.home"))).map(Path::toAbsolutePath).map(Path::toString).collect(Collectors.toList()); Collections.sort(filenames); PlatformImpl.startup(() -> {}); Platform.setImplicitExit(true); Platform.runLater(() -> { final MenuButton button = new MenuButton("Select!"); final DirectoryChooser chooser = new DirectoryChooser(); final MenuItem chooserButton = new MenuItem("Browse"); chooserButton.setOnAction(e -> chooser.showDialog(null)); button.getItems().setAll( chooserButton, MatchSelectionExample.menu("Recent...", System.out::println, filenames), MatchSelectionExample.menu("Favorites...", System.out::println, filenames)); final Stage stage = new Stage(); final Scene scene = new Scene(button); stage.setScene(scene); stage.addEventHandler(KeyEvent.KEY_PRESSED, e -> { if (KeyCode.ESCAPE.equals(e.getCode())) { if (!e.isConsumed()) stage.close(); e.consume(); } }); stage.show(); }); }
Example #25
Source File: TestUtils.java From tcMenu with Apache License 2.0 | 5 votes |
public static Collection<MenuItem> findItemsInMenuWithId(FxRobot robot, String menuToFind) { MenuBar menuBar = robot.lookup("#mainMenu").query(); MenuItem menu = menuBar.getMenus().stream().flatMap(m-> m.getItems().stream()) .filter(m -> menuToFind.equals(m.getId())) .findFirst().orElseThrow(RuntimeException::new); return ((Menu)menu).getItems(); }
Example #26
Source File: BrokerConfigView.java From kafka-message-tool with MIT License | 5 votes |
private MenuItem createMenuItemForDeletingTopic() { final MenuItem deleteTopicMenuItem = new MenuItem("Delete topic"); deleteTopicMenuItem.setOnAction(event -> { final TopicAggregatedSummary summary = topicsTableView.getSelectionModel().selectedItemProperty().get(); try { deleteTopic(kafkaBrokerProxyProperty.get(), summary); } catch (Exception e) { Logger.error("Could not delete topic", e); } }); return deleteTopicMenuItem; }
Example #27
Source File: TagBoard.java From OpenLabeler with Apache License 2.0 | 5 votes |
private void onContextMenuEvent(ContextMenuEvent event) { ObjectTag selected = selectedObjectProperty.get(); if (selected == null) { return; } contextMenu = new ContextMenu(); for (int i = 0; i < 10 && i < Settings.recentNamesProperty.size(); i++) { NameColor nameColor = Settings.recentNamesProperty.get(i); String name = nameColor.getName(); if (name.isEmpty() || name.isBlank()) { continue; } MenuItem mi = new MenuItem(name); mi.setOnAction(value -> { selected.nameProperty().set(name); Settings.recentNamesProperty.addName(name); }); contextMenu.getItems().add(mi); } if (!contextMenu.getItems().isEmpty()) { contextMenu.getItems().add(new SeparatorMenuItem()); } MenuItem editName = new MenuItem(bundle.getString("menu.editName")); editName.setOnAction(value -> { NameEditor editor = new NameEditor(selected.nameProperty().get()); String label = editor.showPopup(event.getScreenX(), event.getScreenY(), getScene().getWindow()); selected.nameProperty().set(label); Settings.recentNamesProperty.addName(label); }); MenuItem delete = new MenuItem(bundle.getString("menu.delete")); delete.setOnAction(value -> deleteSelected(bundle.getString("menu.delete"))); contextMenu.getItems().addAll(editName, delete); contextMenu.setAutoHide(true); contextMenu.show(imageView, event.getScreenX(), event.getScreenY()); event.consume(); }
Example #28
Source File: AnimationControlTreeNode.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread public void fillContextMenu(@NotNull final NodeTree<?> nodeTree, @NotNull final ObservableList<MenuItem> items) { items.add(new PlaySettingsAction(nodeTree, this)); super.fillContextMenu(nodeTree, items); }
Example #29
Source File: ButtonChecker.java From Quelea with GNU General Public License v3.0 | 5 votes |
/** * Check whether the add to schedule button should be set enabled or * disabled. * * @param addSongButton the button to check. */ public void checkAddButton(MenuItem addSongButton) { final MainPanel mainPanel = QueleaApp.get().getMainWindow().getMainPanel(); final LibrarySongList songList = mainPanel.getLibraryPanel().getLibrarySongPanel().getSongList(); if(!songList.focusedProperty().get()) { addSongButton.setDisable(true); return; } if(songList.getListView().getSelectionModel().getSelectedIndex() == -1) { addSongButton.setDisable(true); } else { addSongButton.setDisable(false); } }
Example #30
Source File: BrokerConfigView.java From kafka-message-tool with MIT License | 5 votes |
private ContextMenu getTopicManagementContextMenu(MenuItem deleteTopicMenuItem, MenuItem createTopicMenuItem, MenuItem alterTopicMenuItem, MenuItem topicPropertiesMenuItem) { final ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().setAll(createTopicMenuItem, deleteTopicMenuItem, alterTopicMenuItem, new SeparatorMenuItem(), topicPropertiesMenuItem); return contextMenu; }