javax.swing.JMenu.getItem()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(92)

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

JMenu.getItem介绍

暂无

代码示例

代码示例来源:origin: chewiebug/GCViewer

@Override
public void internalFrameActivated(InternalFrameEvent e) {
  for (int i=2; i < getMenuBar(e).getWindowMenu().getItemCount(); i++) {
    final JMenuItem item = getMenuBar(e).getWindowMenu().getItem(i);
    if (((WindowMenuItemAction)item.getAction()).getInternalFrame() == e.getInternalFrame()) {
      item.setSelected(true);
      break;
    }
  }
  
  getActionMap(e).get(ActionCommands.EXPORT.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.REFRESH.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.WATCH.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.ZOOM.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.ARRANGE.toString()).setEnabled(true);
  // setSelected() does not fire ActionEvent -> both buttons have to be changed
  getMenuBar(e).getWatchMenuItem().setSelected(getSelectedGCDocument(e).isWatched());
  getToolBar(e).getWatchToggleButton().setSelected(getSelectedGCDocument(e).isWatched());
  
  updateMenuItemState(e);
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

addSyntaxItem("XML",  "XMLExample.txt", SYNTAX_STYLE_XML, bg, menu);
addSyntaxItem("YAML", "YamlExample.txt", SYNTAX_STYLE_YAML, bg, menu);
menu.getItem(2).setSelected(true);
mb.add(menu);

代码示例来源:origin: chewiebug/GCViewer

@Override
public void internalFrameClosing(InternalFrameEvent e) {
  JInternalFrame internalFrame = e.getInternalFrame();
  internalFrame.removeInternalFrameListener(this);
  internalFrame.getRootPane().remove(internalFrame);
  if (internalFrame.getRootPane().getComponentCount() == 0) {
    getActionMap(e).get(ActionCommands.ARRANGE.toString()).setEnabled(false);
  }
  
  // remove menuitem from menu and from button group
  JMenu windowMenu = getMenuBar(e).getWindowMenu();
  for (int i = 2; i < windowMenu.getItemCount(); i++) {
    JMenuItem item = windowMenu.getItem(i);
    if (((WindowMenuItemAction) item.getAction()).getInternalFrame() == internalFrame) {
      getMenuBar(e).removeFromWindowMenuGroup(item);
      break;
    }
  }
  // if this internalFrame is the last to be open, update the menu state
  // -> otherwise any settings done by the user are lost
  if (getGCViewerGui(e).getDesktopPane().getComponentCount() == 1) {
    updateMenuItemState(e);
    // set same menustate, when the last is closed as is set for deactivated
    internalFrameDeactivated(e);
  }
  // if some thread is still loading, it should stop now
  getSelectedGCDocument(e).getGCResources().stream().forEach(gcResource -> gcResource.setIsReadCancelled(true));
}

代码示例来源:origin: ron190/jsql-injection

private void setListener(JMenuItem item, ActionListener listener) {
  if (item instanceof JMenu) {
    JMenu menuContainingItems = (JMenu) item;
    int n = menuContainingItems.getItemCount();
    for (int i = 0 ; i < n ; i++) {
      this.setListener(menuContainingItems.getItem(i), listener);
    }
  } else if (item != null) { // null means separator
    item.addActionListener(listener);
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(false);
    MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setSelected(false);
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.BLIND.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(true);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.TIME.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(true);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    JMenuItem menuItemStrategy = MediatorGui.managerDatabase().getMenuStrategy().getItem(i);
    if (menuItemStrategy.getText().equals(StrategyInjection.ERROR.toString())) {
      JMenu menuError = (JMenu) menuItemStrategy;
      menuError.setEnabled(true);
      
      // Fix #46578: ArrayIndexOutOfBoundsException on getItem()
      if (0 <= this.indexMethodError && this.indexMethodError < menuError.getItemCount()) {
        menuError.getItem(this.indexMethodError).setEnabled(true);
      }
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.BLIND.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(false);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.TIME.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(false);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.NORMAL.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(true);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.NORMAL.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(false);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  // Fix #36975: ArrayIndexOutOfBoundsException on getItem()
  // Fix #40352: NullPointerException on ?
  try {
    for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
      if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.ERROR.toString())) {
        ((JMenu) MediatorGui.managerDatabase().getMenuStrategy().getItem(i)).getItem(this.indexMethodError).setEnabled(false);
        break;
      }
    }
  } catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
    LOGGER.error(e, e);
  }
}

代码示例来源:origin: apache/pdfbox

@Override
public void ancestorRemoved(AncestorEvent ancestorEvent)
{
  boolean isFirstEntrySkipped = false;
  zoomMenu.setEnableMenu(false);
  rotationMenu.setEnableMenu(false);
  
  JMenu menuInstance = viewMenu.getMenu();
  int itemCount = menuInstance.getItemCount();
  
  for (int i = 0; i< itemCount; i++)
  {
    JMenuItem item = menuInstance.getItem(i);
    // skip the first JMenuItem as this shall always be shown
    if (item != null)
    {
      if (!isFirstEntrySkipped)
      {
        isFirstEntrySkipped = true;
      }
      else
      {
        item.setEnabled(false);
        item.removeActionListener(this);
      }
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  MediatorGui.managerDatabase().getMenuStrategy().setText(StrategyInjection.BLIND.toString());
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.BLIND.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setSelected(true);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  MediatorGui.managerDatabase().getMenuStrategy().setText(StrategyInjection.NORMAL.toString());
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.NORMAL.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setSelected(true);
      break;
    }
  }
}

代码示例来源:origin: apache/pdfbox

@Override
public void ancestorAdded(AncestorEvent ancestorEvent)
{
  zoomMenu.addMenuListeners(this);
  zoomMenu.setEnableMenu(true);
  
  rotationMenu = RotationMenu.getInstance();
  rotationMenu.addMenuListeners(this);
  rotationMenu.setEnableMenu(true);
  
  viewMenu = ViewMenu.getInstance(null);
  JMenu menuInstance = viewMenu.getMenu();
  int itemCount = menuInstance.getItemCount();
  
  for (int i = 0; i< itemCount; i++)
  {
    JMenuItem item = menuInstance.getItem(i);
    if (item != null)
    {
      item.setEnabled(true);
      item.addActionListener(this);
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  MediatorGui.managerDatabase().getMenuStrategy().setText(StrategyInjection.TIME.toString());
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    if (MediatorGui.managerDatabase().getMenuStrategy().getItem(i).getText().equals(StrategyInjection.TIME.toString())) {
      MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setSelected(true);
      break;
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void execute() {
  if (MediatorGui.managerDatabase() == null) {
    LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass());
  }
  
  MediatorGui.managerDatabase().getMenuStrategy().setText(StrategyInjection.ERROR.toString());
  
  JMenu menuError = (JMenu) MediatorGui.managerDatabase().getMenuStrategy().getMenuComponent(2);
  int indexError = StrategyInjection.ERROR.instance().getIndexMethod();
  String nameError = MediatorModel.model().getVendor().instance().getXmlModel().getStrategy().getError().getMethod().get(indexError).getName();
  
  for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) {
    // Fix #44635: ArrayIndexOutOfBoundsException on getItem()
    try {
      if (menuError.getItem(i).getText().equals(nameError)) {
        menuError.getItem(i).setSelected(true);
        MediatorGui.managerDatabase().getMenuStrategy().setText(nameError);
        break;
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      LOGGER.error(e, e);
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

MediatorGui.managerDatabase().getMenuStrategy().getItem(i).setEnabled(false);
((JMenu) MediatorGui.managerDatabase().getMenuStrategy().getItem(2)).removeAll();
MediatorGui.managerDatabase().getGroupStrategy().clearSelection();

相关文章