当前位置: 首页>>代码示例>>Java>>正文


Java JMenu.setIcon方法代码示例

本文整理汇总了Java中javax.swing.JMenu.setIcon方法的典型用法代码示例。如果您正苦于以下问题:Java JMenu.setIcon方法的具体用法?Java JMenu.setIcon怎么用?Java JMenu.setIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JMenu的用法示例。


在下文中一共展示了JMenu.setIcon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureMenu

import javax.swing.JMenu; //导入方法依赖的package包/类
void configureMenu(final JComponent parent, final JMenu menu) {
    // make sure it will draw it's border so we can have rollovers and selection
    menu.setBorderPainted(true);
    //install the wrapper icon if not a toplevel JMenu
    if(!isTopLevelMenu(menu)) {
        if(!(menu.getIcon() instanceof WrapperIcon)) {
            menu.setIcon(new WrapperIcon(menu.getIcon()));
        }
    }
    
    // configure the maps and popups
    JPopupMenu popup = menu.getPopupMenu();
    menuPopupUIMap.put(menu, popup.getUI());
    popup.setUI(new VisualDesignerPopupMenuUI(this, popup.getUI()));
    
    // get all of the components in this menu
    Component[] subComps = menu.getMenuComponents();
    // if this isn't the first time this menu has been opened then the sub components
    // will have been moved to the popupPanel already, so we will find them there instead.
    JPanel popupPanel = getPopupFactory().containerMap.get(menu);
    if(popupPanel != null) {
        subComps = popupPanel.getComponents();
    }
    
    RADVisualContainer menuRAD = (RADVisualContainer) formDesigner.getMetaComponent(menu);
    registerForm(menuRAD,menu);
    
    // recurse for sub-menus
    for(Component c : subComps) {
        if(c instanceof JMenu) {
            configureMenu(menu, (JMenu)c);
            RADComponent rad = formDesigner.getMetaComponent(c);
            registerForm((RADVisualContainer)rad,(JMenu)c);
        } else {
            configureMenuItem(menu, (JComponent) c);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:MenuEditLayer.java

示例2: invoke

import javax.swing.JMenu; //导入方法依赖的package包/类
/**
 * @see java.lang.reflect.InvocationHandler.invoke(Object, Method, Object[])
 */
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  Object result = null;
  // Customize pop-up menu
  if (method.getName().equals("customizePopUpMenu")) {
    // The contextual menu of the project view, where we should add the Git sub-menu.
    JPopupMenu projectContextMenu = (JPopupMenu) args[0];

    // Proceed only if the selected file pertain to a Git repository
    if (areSelectedFilesFromGitRepo()) {
      projectContextMenu.addSeparator();
      JMenu gitMenu = new JMenu(translator.getTranslation(Tags.PROJECT_VIEW_GIT_CONTEXTUAL_MENU_ITEM));
      ImageUtilities imageUtilities = PluginWorkspaceProvider.getPluginWorkspace().getImageUtilities();
      URL resource = getClass().getResource(ImageConstants.GIT_ICON);
      if (resource != null) {
        ImageIcon icon = (ImageIcon) imageUtilities.loadIcon(resource);
        gitMenu.setIcon(icon);
      }
      for (AbstractAction action : gitActionsProvider.getActionsForProjectViewSelection()) {
         gitMenu.add(action);
       }
      projectContextMenu.add(gitMenu);
    }
  }

  return result;
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:31,代码来源:ProjectPopupMenuCustomizerInvocationHandler.java

示例3: getMenuPresenter

import javax.swing.JMenu; //导入方法依赖的package包/类
public JMenuItem getMenuPresenter() {
    // beware, we shouldn't cache menu intstance, because getMenuPresenter
    // can be legally called several times and menu component cannot be
    // contained in more than one component hierarchy
    JMenu menu = new org.openide.awt.JMenuPlus();
    Mnemonics.setLocalizedText(menu, getName());
    menu.setHorizontalTextPosition(JMenu.RIGHT);
    menu.setHorizontalAlignment(JMenu.LEFT);
    menu.setIcon(getIcon());
    HelpCtx.setHelpIDString(menu, WorkspaceSwitchAction.class.getName());

    final WindowManager pool = WindowManager.getDefault();

    final Hashtable menu2Workspace = new Hashtable(10);

    // ^ maps listener on workspace
    final Hashtable workspace2Menu = new Hashtable(10);

    // ^ maps workspace to menuitem
    final Hashtable workspace2Listener = new Hashtable(10);

    // ^ maps workspace to action listener
    final Workspace[] currentDeskRef = new Workspace[1];
    currentDeskRef[0] = pool.getCurrentWorkspace();

    // attach all workspaces
    Workspace[] workspaces = pool.getWorkspaces();

    for (int i = 0; i < workspaces.length; i++) {
        attachWorkspace(workspaces[i], currentDeskRef, workspace2Menu, menu2Workspace, workspace2Listener, menu);
    }

    // check on currently active workspace
    JRadioButtonMenuItem curItem = (JRadioButtonMenuItem) workspace2Menu.get(currentDeskRef[0]);

    if (curItem != null) {
        curItem.setSelected(true);
    }

    // listen to the changes in workspaces
    pool.addPropertyChangeListener(
        getWorkspacePoolListener(workspace2Menu, menu2Workspace, workspace2Listener, currentDeskRef, menu)
    );

    return menu;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:WorkspaceSwitchAction.java


注:本文中的javax.swing.JMenu.setIcon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。