javafx.scene.control.MenuItem.setOnAction()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(15.4k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中javafx.scene.control.MenuItem.setOnAction()方法的一些代码示例,展示了MenuItem.setOnAction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setOnAction()方法的具体详情如下:
包路径:javafx.scene.control.MenuItem
类名称:MenuItem
方法名:setOnAction

暂无

代码示例

代码示例来源: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: 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: speedment/speedment

@Override
  void installMenuItems(ProjectTreeComponent projectTree) {
    projectTree.installContextMenu(TableProperty.class, (treeCell, node) -> {
      final MenuItem enableColumns  = new MenuItem("Enable All Columns");
      final MenuItem disableColumns = new MenuItem("Disable All Columns");

      enableColumns.setOnAction(ev ->
        DocumentUtil.traverseOver(node)
          .filter(ColumnProperty.class::isInstance)
          .forEach(doc -> ((ColumnProperty) doc).enabledProperty().setValue(true))
      );

      disableColumns.setOnAction(ev ->
        DocumentUtil.traverseOver(node)
          .filter(ColumnProperty.class::isInstance)
          .forEach(doc -> ((ColumnProperty) doc).enabledProperty().setValue(false))
      );

      return Stream.of(enableColumns, disableColumns);
    });
  }
}

代码示例来源:origin: speedment/speedment

@Override
  void installMenuItems(ProjectTreeComponent projectTree) {
    projectTree.installContextMenu(SchemaProperty.class, (treeCell, node) -> {
      final MenuItem enableTables  = new MenuItem("Enable All Tables");
      final MenuItem disableTables = new MenuItem("Disable All Tables");

      enableTables.setOnAction(ev ->
        DocumentUtil.traverseOver(node)
          .filter(TableProperty.class::isInstance)
          .forEach(doc -> ((TableProperty) doc).enabledProperty().setValue(true))
      );

      disableTables.setOnAction(ev ->
        DocumentUtil.traverseOver(node)
          .filter(TableProperty.class::isInstance)
          .forEach(doc -> ((TableProperty) doc).enabledProperty().setValue(false))
      );

      return Stream.of(enableTables, disableTables);
    });
  }
}

代码示例来源:origin: speedment/speedment

private <DOC extends DocumentProperty> Stream<MenuItem>
  installForDocumentType(TreeCell<DocumentProperty> treeCell, DOC node) {
    final MenuItem expandAll   = new MenuItem("Expand All", ProjectTreeIcon.BOOK_OPEN.view());
    final MenuItem collapseAll = new MenuItem("Collapse All", ProjectTreeIcon.BOOK.view());

    expandAll.setOnAction(ev ->
      DocumentUtil.traverseOver(node)
        .filter(HasExpandedProperty.class::isInstance)
        .forEach(doc -> ((HasExpandedProperty) doc).expandedProperty().setValue(true))
    );

    collapseAll.setOnAction(ev ->
      DocumentUtil.traverseOver(node)
        .filter(HasExpandedProperty.class::isInstance)
        .forEach(doc -> ((HasExpandedProperty) doc).expandedProperty().setValue(false))
    );

    return Stream.of(expandAll, collapseAll);
  }
}

代码示例来源: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: pmd/pmd

@Override
protected void beforeParentInit() {
  try {
    SettingsPersistenceUtil.restoreProperties(this, DesignerUtil.getSettingsFile());
  } catch (Exception e) {
    // shouldn't prevent the app from opening
    // in case the file is corrupted, it will be overwritten on shutdown
    e.printStackTrace();
  }
  initializeViewAnimation();
  licenseMenuItem.setOnAction(e -> showLicensePopup());
  openFileMenuItem.setOnAction(e -> onOpenFileClicked());
  openRecentMenu.setOnAction(e -> updateRecentFilesMenu());
  openRecentMenu.setOnShowing(e -> updateRecentFilesMenu());
  fileMenu.setOnShowing(e -> onFileMenuShowing());
  setupAuxclasspathMenuItem.setOnAction(e -> sourceEditorController.showAuxclasspathSetupPopup(designerRoot));
  openEventLogMenuItem.setOnAction(e -> eventLogController.getValue().showPopup());
  openEventLogMenuItem.textProperty().bind(
    designerRoot.getLogger().numNewLogEntriesProperty().map(i -> "Exception log (" + (i > 0 ? i : "no") + " new)")
  );
}

代码示例来源:origin: jfoenixadmin/JFoenix

item1.setOnAction((action) -> {
  ((JFXTreeTableView) getTreeTableView()).group(this);
});
MenuItem item2 = new MenuItem("UnGroup");
item2.setOnAction((action) -> {
  ((JFXTreeTableView) getTreeTableView()).unGroup(this);
});

代码示例来源:origin: pmd/pmd

editItem.setOnAction(e -> {
  PropertyDescriptorSpec spec = this.getSelectionModel().getSelectedItem();
  if (spec != null) {
removeItem.setOnAction(e -> {
  PropertyDescriptorSpec selected = this.getSelectionModel().getSelectedItem();
  if (selected != null) {
addItem.setOnAction(e -> onAddPropertyClicked());
addItem2.setOnAction(e -> onAddPropertyClicked());

代码示例来源:origin: pmd/pmd

item.setOnAction(e -> {
  try {
    Stage popup = new Stage();

代码示例来源:origin: speedment/speedment

item.setOnAction(menuItemClicked);

代码示例来源: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: torakiki/pdfsam

@Inject
  public ModulesMenu(List<Module> modules) {
    super(DefaultI18nContext.getInstance().i18n("_Modules"));
    setId("modulesMenu");
    Map<ModuleCategory, Menu> moduleSubmenus = new HashMap<>();
    for (final Module currentModule : modules) {
      ModuleCategory category = currentModule.descriptor().category;
      Menu currentMenu = moduleSubmenus.get(category);
      if (currentMenu == null) {
        currentMenu = new Menu(category.getDescription());
        moduleSubmenus.put(category, currentMenu);
      }
      MenuItem moduleMenu = new MenuItem(currentModule.descriptor().getName());
      moduleMenu.setOnAction(e -> eventStudio().broadcast(activeteModule(currentModule.id())));
      currentMenu.getItems().add(moduleMenu);
    }
    getItems().addAll(moduleSubmenus.values());
  }
}

代码示例来源:origin: torakiki/pdfsam

public ClearButton(String ownerModule) {
  this.ownerModule = defaultString(ownerModule);
  getStyleClass().addAll(Style.BUTTON.css());
  getStyleClass().add("pdfsam-split-button");
  setTooltip(new Tooltip(DefaultI18nContext.getInstance().i18n("Removes every document")));
  setText(DefaultI18nContext.getInstance().i18n("_Clear"));
  setOnAction(this::clear);
  MenuItem clearAllSettings = new MenuItem();
  clearAllSettings.setText(DefaultI18nContext.getInstance().i18n("C_lear all settings"));
  clearAllSettings.setOnAction(this::clearAll);
  getItems().add(clearAllSettings);
}

代码示例来源: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 initContextMenu() {
  MenuItem infoItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Document properties"),
      MaterialDesignIcon.INFORMATION_OUTLINE);
  infoItem.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.ALT_DOWN));
  infoItem.setOnAction(
      e -> Platform.runLater(() -> eventStudio().broadcast(new ShowPdfDescriptorRequest(descriptor))));
  removeSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Remove"), MaterialDesignIcon.MINUS);
  removeSelected.setOnAction(e -> eventStudio().broadcast(new ClearModuleEvent(), getOwnerModule()));
  MenuItem setDestinationItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set destination"),
      MaterialDesignIcon.AIRPLANE_LANDING);
  setDestinationItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.ALT_DOWN));
  setDestinationItem.setOnAction(e -> eventStudio()
      .broadcast(requestDestination(descriptor.getFile(), getOwnerModule()), getOwnerModule()));
  MenuItem openFileItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open"),
      MaterialDesignIcon.FILE_PDF_BOX);
  openFileItem.setOnAction(e -> eventStudio().broadcast(new OpenFileRequest(descriptor.getFile())));
  MenuItem openFolderItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open Folder"),
      MaterialDesignIcon.FOLDER_OUTLINE);
  openFolderItem
      .setOnAction(e -> eventStudio().broadcast(new OpenFileRequest(descriptor.getFile().getParentFile())));
  field.getTextField().setContextMenu(new ContextMenu(setDestinationItem, new SeparatorMenuItem(), removeSelected,
      new SeparatorMenuItem(), infoItem, openFileItem, openFolderItem));
}

代码示例来源:origin: torakiki/pdfsam

private void initTopSectionContextMenu(ContextMenu contextMenu, boolean hasRanges) {
  MenuItem setDestinationItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set destination"),
      MaterialDesignIcon.AIRPLANE_LANDING);
  setDestinationItem.setOnAction(e -> eventStudio().broadcast(
      requestDestination(getSelectionModel().getSelectedItem().descriptor().getFile(), getOwnerModule()),
      getOwnerModule()));
  setDestinationItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.ALT_DOWN));
  selectionChangedConsumer = e -> setDestinationItem.setDisable(!e.isSingleSelection());
  contextMenu.getItems().add(setDestinationItem);
  if (hasRanges) {
    MenuItem setPageRangesItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set as range for all"),
        MaterialDesignIcon.FORMAT_INDENT_INCREASE);
    setPageRangesItem.setOnAction(e -> eventStudio().broadcast(
        new SetPageRangesRequest(getSelectionModel().getSelectedItem().pageSelection.get()),
        getOwnerModule()));
    setPageRangesItem.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN));
    selectionChangedConsumer = selectionChangedConsumer
        .andThen(e -> setPageRangesItem.setDisable(!e.isSingleSelection()));
    contextMenu.getItems().add(setPageRangesItem);
  }
  contextMenu.getItems().add(new SeparatorMenuItem());
}

代码示例来源: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: torakiki/pdfsam

removeSelected.setOnAction(e -> eventStudio().broadcast(new RemoveSelectedEvent(), getOwnerModule()));
removeSelected.setAccelerator(new KeyCodeCombination(KeyCode.DELETE));
contextMenu.getItems().add(removeSelected);
      MaterialDesignIcon.CHEVRON_DOUBLE_UP);
  moveTopSelected
      .setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.TOP), getOwnerModule()));
      .setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.UP), getOwnerModule()));
      .setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.DOWN), getOwnerModule()));
  moveBottomSelected.setOnAction(
      e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.BOTTOM), getOwnerModule()));
  MenuItem duplicateItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Duplicate"),
      MaterialDesignIcon.CONTENT_DUPLICATE);
  duplicateItem.setOnAction(e -> eventStudio().broadcast(new DuplicateSelectedEvent(), getOwnerModule()));
  duplicateItem.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT2, KeyCombination.ALT_DOWN));

代码示例来源:origin: torakiki/pdfsam

copyItem.setId("copyLogMenuItem");
copyItem.setAccelerator(new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN));
copyItem.setOnAction(e -> copyLog(logView.getSelectionModel().getSelectedItems()));
clearItem.setOnAction(e -> logView.getItems().clear());
selectAllItem.setOnAction(e -> logView.getSelectionModel().selectAll());
saveItem.setOnAction(e -> saveLog());

相关文章