當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。