本文整理了Java中javafx.scene.control.MenuItem
类的一些代码示例,展示了MenuItem
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem
类的具体详情如下:
包路径:javafx.scene.control.MenuItem
类名称:MenuItem
暂无
代码示例来源:origin: speedment/speedment
/**
* Adds a new {@link MenuItem} factory to the end of this handler.
*
* @param text the text to show
* @param action the action to perform when the button is pressed
* @return this instance
*/
default MenuBarTabHandler addMenuItem(String text, EventHandler<ActionEvent> action) {
return set(text.replace("_", "").replace(" ", "-").toLowerCase(), () -> {
final MenuItem item = new MenuItem(text);
item.setOnAction(action);
return item;
});
}
代码示例来源:origin: pmd/pmd
autoCompletePopup.getItems().get(focusIdx).getOnAction().handle(new ActionEvent());
代码示例来源:origin: torakiki/pdfsam
private MenuItem createMenuItem(String text, MaterialDesignIcon icon) {
MenuItem item = new MenuItem(text);
MaterialDesignIconFactory.get().setIcon(item, icon, "1.1em");
item.setDisable(true);
return item;
}
代码示例来源:origin: speedment/speedment
/**
* Adds a new {@link MenuItem} factory to the end of this handler.
*
* @param text the text to show
* @param icon the icon to show
* @param action the action to perform when the button is pressed
* @return this instance
*/
default MenuBarTabHandler addMenuItem(String text, SpeedmentIcon icon, EventHandler<ActionEvent> action) {
return set(text.replace("_", "").replace(" ", "-").toLowerCase(), () -> {
final MenuItem item = new MenuItem(text);
item.setGraphic(icon.view());
item.setOnAction(action);
return item;
});
}
代码示例来源:origin: pmd/pmd
private void updateRecentFilesMenu() {
List<MenuItem> items = new ArrayList<>();
List<File> filesToClear = new ArrayList<>();
for (final File f : recentFiles) {
if (f.exists() && f.isFile()) {
CustomMenuItem item = new CustomMenuItem(new Label(f.getName()));
item.setOnAction(e -> loadSourceFromFile(f));
item.setMnemonicParsing(false);
Tooltip.install(item.getContent(), new Tooltip(f.getAbsolutePath()));
items.add(item);
} else {
filesToClear.add(f);
}
}
recentFiles.removeAll(filesToClear);
if (items.isEmpty()) {
openRecentMenu.setDisable(true);
return;
}
Collections.reverse(items);
items.add(new SeparatorMenuItem());
MenuItem clearItem = new MenuItem();
clearItem.setText("Clear menu");
clearItem.setOnAction(e -> {
recentFiles.clear();
openRecentMenu.setDisable(true);
});
items.add(clearItem);
openRecentMenu.getItems().setAll(items);
}
代码示例来源:origin: torakiki/pdfsam
@Inject
AppContextMenu(WorkspaceMenu workspace, ModulesMenu modulesMenu) {
MenuItem exit = new MenuItem(DefaultI18nContext.getInstance().i18n("E_xit"));
exit.setOnAction(e -> Platform.exit());
exit.setAccelerator(new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN));
getItems().addAll(workspace, modulesMenu);
if (!Boolean.getBoolean(PreferencesDashboardItem.PDFSAM_DISABLE_SETTINGS_DEPRECATED)
&& !Boolean.getBoolean(PreferencesDashboardItem.PDFSAM_DISABLE_SETTINGS)) {
MenuItem settings = new MenuItem(DefaultI18nContext.getInstance().i18n("_Settings"));
settings.setOnAction(
e -> eventStudio().broadcast(new SetActiveDashboardItemRequest(PreferencesDashboardItem.ID)));
getItems().add(settings);
}
getItems().addAll(new SeparatorMenuItem(), exit);
}
}
代码示例来源:origin: com.powsybl/powsybl-gse-security-analysis
private static <T> void addContextMenu(CheckListView<T> listView) {
listView.setOnContextMenuRequested(event -> {
ContextMenu contextMenu = new ContextMenu();
MenuItem selectAll = new MenuItem(RESOURCE_BUNDLE.getString("SelectAll"));
selectAll.disableProperty().bind(Bindings.equal(listView.getItems().size(), Bindings.size(listView.getCheckModel().getCheckedIndices())));
selectAll.setOnAction(event2 -> listView.getCheckModel().checkAll());
MenuItem deselectAll = new MenuItem(RESOURCE_BUNDLE.getString("DeselectAll"));
deselectAll.disableProperty().bind(Bindings.isEmpty(listView.getCheckModel().getCheckedIndices()));
deselectAll.setOnAction(event2 -> listView.getCheckModel().clearChecks());
contextMenu.getItems().addAll(selectAll, deselectAll);
contextMenu.show(listView, event.getScreenX(), event.getScreenY());
});
}
代码示例来源:origin: torakiki/pdfsam
MenuItem copyItem = new MenuItem(i18n.i18n("Copy"));
copyItem.setId("copyLogMenuItem");
copyItem.setAccelerator(new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN));
copyItem.setOnAction(e -> copyLog(logView.getSelectionModel().getSelectedItems()));
copyItem.disableProperty().bind(new BooleanBinding() {
MenuItem clearItem = new MenuItem(i18n.i18n("Clear"));
clearItem.setId("clearLogMenuItem");
clearItem.setOnAction(e -> logView.getItems().clear());
clearItem.disableProperty().bind(new BooleanBinding() {
MenuItem selectAllItem = new MenuItem(i18n.i18n("Select all"));
selectAllItem.setId("selectAllLogMenuItem");
selectAllItem.setOnAction(e -> logView.getSelectionModel().selectAll());
selectAllItem.disableProperty().bind(clearItem.disableProperty());
MenuItem saveItem = new MenuItem(i18n.i18n("Save log"));
saveItem.setId("saveLogMenuItem");
saveItem.setOnAction(e -> saveLog());
saveItem.disableProperty().bind(clearItem.disableProperty());
SeparatorMenuItem separator = new SeparatorMenuItem();
logView.setContextMenu(new ContextMenu(copyItem, clearItem, selectAllItem, separator, saveItem));
代码示例来源:origin: stackoverflow.com
public void addStorehouseMenuListeners( EventHandler<ActionEvent> eventHandler )
{
MenuItem displayStorehouse = storheouseMenu.getItems().get(0);
displayStorehouse.setOnAction( eventHandler );
}
代码示例来源:origin: torakiki/pdfsam
@Inject
public WorkspaceMenu(RecentWorkspacesService service) {
super(DefaultI18nContext.getInstance().i18n("_Workspace"));
this.service = service;
setId("workspaceMenu");
MenuItem load = new MenuItem(DefaultI18nContext.getInstance().i18n("_Load"));
load.setId("loadWorkspace");
load.setOnAction(e -> loadWorkspace());
MenuItem save = new MenuItem(DefaultI18nContext.getInstance().i18n("_Save"));
save.setOnAction(e -> saveWorkspace());
save.setId("saveWorkspace");
recent = new Menu(DefaultI18nContext.getInstance().i18n("Recen_ts"));
recent.setId("recentWorkspace");
service.getRecentlyUsedWorkspaces().stream().map(WorkspaceMenuItem::new).forEach(recent.getItems()::add);
MenuItem clear = new MenuItem(DefaultI18nContext.getInstance().i18n("_Clear recents"));
clear.setOnAction(e -> clearWorkspaces());
clear.setId("clearWorkspaces");
getItems().addAll(load, save, new SeparatorMenuItem(), recent, clear);
eventStudio().addAnnotatedListeners(this);
}
代码示例来源:origin: torakiki/pdfsam
private void initBottomSectionContextMenu(ContextMenu contextMenu) {
MenuItem copyItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Copy to clipboard"),
MaterialDesignIcon.CONTENT_COPY);
copyItem.setOnAction(e -> copySelectedToClipboard());
MenuItem infoItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Document properties"),
MaterialDesignIcon.INFORMATION_OUTLINE);
infoItem.setOnAction(e -> Platform.runLater(() -> eventStudio()
.broadcast(new ShowPdfDescriptorRequest(getSelectionModel().getSelectedItem().descriptor()))));
MenuItem openFileItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open"),
MaterialDesignIcon.FILE_PDF_BOX);
openFileItem.setOnAction(e -> eventStudio()
.broadcast(new OpenFileRequest(getSelectionModel().getSelectedItem().descriptor().getFile())));
MenuItem openFolderItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open Folder"),
MaterialDesignIcon.FOLDER_OUTLINE);
openFolderItem.setOnAction(e -> eventStudio().broadcast(
new OpenFileRequest(getSelectionModel().getSelectedItem().descriptor().getFile().getParentFile())));
copyItem.setAccelerator(new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN));
infoItem.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.ALT_DOWN));
openFileItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
openFolderItem.setAccelerator(
new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN, KeyCombination.ALT_DOWN));
contextMenu.getItems().addAll(new SeparatorMenuItem(), copyItem, infoItem, openFileItem, openFolderItem);
selectionChangedConsumer = selectionChangedConsumer.andThen(e -> {
copyItem.setDisable(e.isClearSelection());
infoItem.setDisable(!e.isSingleSelection());
openFileItem.setDisable(!e.isSingleSelection());
openFolderItem.setDisable(!e.isSingleSelection());
});
}
代码示例来源:origin: com.powsybl/powsybl-gse-util
private MenuItem createDeleteNodeMenuItem(List<? extends TreeItem<N>> selectedTreeItems) {
MenuItem deleteMenuItem = new MenuItem(RESOURCE_BUNDLE.getString("Delete"), Glyph.createAwesomeFont('\uf1f8').size(ICON_SIZE));
if (selectedTreeItems.size() == 1) {
TreeItem<N> selectedTreeItem = selectedTreeItems.get(0);
N selectedTreeItemValue = selectedTreeItem.getValue();
if (selectedTreeItemValue instanceof Folder) {
Folder folder = (Folder) selectedTreeItemValue;
if (!folder.getChildren().isEmpty()) {
deleteMenuItem.setDisable(true);
}
} else if (selectedTreeItemValue instanceof Project) {
Project project = (Project) selectedTreeItemValue;
if (openedProjects.contains(project.getId())) {
deleteMenuItem.setDisable(true);
}
}
} else {
selectionContainsOpenedProjects(selectedTreeItems, deleteMenuItem);
}
deleteMenuItem.setOnAction(event -> createDeleteAlert(selectedTreeItems));
deleteMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.DELETE));
return deleteMenuItem;
}
代码示例来源:origin: com.aquafx-project/aquafx
Menu item1 = new Menu("Item 1");
Menu item2 = new Menu("List item 2");
MenuItem item3 = new MenuItem("List item 3");
item3.setDisable(true);
MenuItem item4 = new MenuItem("List Item 4");
item2.getItems().addAll(item3, item4);
MenuItem item5 = new MenuItem("List Item 5");
item5.setAccelerator(KeyCombination.keyCombination("shortcut+H"));
MenuItem item6 = new MenuItem("List Item 6");
item6.setAccelerator(KeyCombination.keyCombination("Alt+shortcut+H"));
MenuItem item7 = new MenuItem("List Item 7");
item7.setDisable(true);
item1.getItems().addAll(new MenuItem("list item 1"), new SeparatorMenuItem(), item2,
new SeparatorMenuItem(), item5, item6, item7);
item8.getItems().addAll(new MenuItem("List Item 9"));
item10.getItems().addAll(new MenuItem("List Item 11"));
代码示例来源:origin: org.copper-engine/copper-monitoring-client
public MenuItem createShowFormMenuItem() {
MenuItem menuItem = new MenuItem();
menuItem.setText(title);
menuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
createForm().show();
}
});
menuItem.setDisable(!enabled);
return menuItem;
}
代码示例来源:origin: ssaring/sportstracker
private MenuItem createContextMenuItem(final String id, final String resourceKey, //
final EventHandler<ActionEvent> handler) {
final MenuItem menuItem = new MenuItem(getContext().getResources().getString(resourceKey));
menuItem.setId(id);
menuItem.setOnAction(handler);
menuItem.getStyleClass().add("contextMenuItem");
return menuItem;
}
代码示例来源:origin: no.tornado/tornadofx-controls
public Node apply(MultiSelect<E> multiSelect, E item) {
SplitMenuButton button = new SplitMenuButton();
button.setText(multiSelect.getConverter().toString(item));
MenuItem remove = new MenuItem(String.format("Remove %s", item));
remove.setOnAction(event -> {
int index = multiSelect.getChildrenUnmodifiable().indexOf(button);
multiSelect.getItems().remove(item);
multiSelect.getChildrenUnmodifiable().get(index).requestFocus();
});
button.getItems().add(remove);
button.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.BACK_SPACE)
remove.getOnAction().handle(null);
});
return button;
}
}
代码示例来源:origin: com.aquafx-project/aquafx
static MenuItem[] createMenuItems(int numberOfItems) {
ArrayList<MenuItem> items = new ArrayList<MenuItem>();
if (numberOfItems < 26) {
for(int i=0; i<numberOfItems; i++) {
items.add(new MenuItem("Item "+LETTERS[i]));
}
} else {
for(int i=0; i<numberOfItems; i++) {
items.add(new MenuItem("Item "+i));
}
}
return items.toArray(new MenuItem[items.size()]);
}
代码示例来源:origin: org.codehaus.griffon/griffon-javafx
requireNonNull(action, ERROR_ACTION_NULL);
action.onActionProperty().addListener((v, o, n) -> control.setOnAction(n));
control.setOnAction(action.getOnAction());
action.nameProperty().addListener((v, o, n) -> runInsideUIThread(() -> control.setText(n)));
runInsideUIThread(() -> control.setText(action.getName()));
action.enabledProperty().addListener((v, o, n) -> runInsideUIThread(() -> control.setDisable(!n)));
runInsideUIThread(() -> control.setDisable(!action.getEnabled()));
action.acceleratorProperty().addListener((v, o, n) -> runInsideUIThread(() -> control.setAccelerator(n)));
runInsideUIThread(() -> control.setAccelerator(action.getAccelerator()));
action.visibleProperty().addListener((v, o, n) -> runInsideUIThread(() -> control.setVisible(n)));
runInsideUIThread(() -> control.setVisible(action.isVisible()));
代码示例来源:origin: org.controlsfx/controlsfx
private static void unconfigure(final MenuItem menuItem) {
if (menuItem == null || !(menuItem.getOnAction() instanceof Action)) {
return;
}
Action action = (Action) menuItem.getOnAction();
menuItem.styleProperty().unbind();
menuItem.textProperty().unbind();
menuItem.disableProperty().unbind();
menuItem.acceleratorProperty().unbind();
menuItem.graphicProperty().unbind();
action.getProperties().removeListener(new MenuItemPropertiesMapChangeListener<>(menuItem, action));
if (menuItem instanceof RadioMenuItem) {
((RadioMenuItem) menuItem).selectedProperty().unbindBidirectional(action.selectedProperty());
} else if (menuItem instanceof CheckMenuItem) {
((CheckMenuItem) menuItem).selectedProperty().unbindBidirectional(action.selectedProperty());
}
menuItem.setOnAction(null);
}
代码示例来源:origin: org.drombler.commons/drombler-commons-action-fx
/**
* Configures a {@link MenuItem} with the specified action.
*
* @param menuItem the menu item to configre
* @param action the action
* @param iconSize the icon size
*/
public static void configureMenuItem(MenuItem menuItem, FXAction action, int iconSize) {
menuItem.setMnemonicParsing(true);
menuItem.textProperty().bind(action.displayNameProperty());
menuItem.acceleratorProperty().bind(action.acceleratorProperty());
menuItem.setOnAction(action);
menuItem.disableProperty().bind(action.enabledProperty().not());
if (action.getGraphicFactory() != null) {
Node graphic = action.getGraphicFactory().createGraphic(iconSize);
if (graphic != null) {
menuItem.setGraphic(graphic);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!