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


Java JMenuBar类代码示例

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


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

示例1: postProcessKeyEvent

import javax.swing.JMenuBar; //导入依赖的package包/类
public boolean postProcessKeyEvent(KeyEvent ev) {
    if (ev.isConsumed())
        return false;

    if (processShortcut(ev))
        return true;

    Window w = SwingUtilities.windowForComponent(ev.getComponent());        
    if (w instanceof Dialog && !WindowManagerImpl.isSeparateWindow(w))
        return false;
    
    JFrame mw = (JFrame)WindowManagerImpl.getInstance().getMainWindow();
    if (w == mw) {
        return false;
    }

    JMenuBar mb = mw.getJMenuBar();
    if (mb == null)
        return false;
    boolean pressed = (ev.getID() == KeyEvent.KEY_PRESSED);        
    boolean res = invokeProcessKeyBindingsForAllComponents(ev, mw, pressed);
    
    if (res)
        ev.consume();
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ShortcutAndMenuKeyEventProcessor.java

示例2: init

import javax.swing.JMenuBar; //导入依赖的package包/类
@Override
public void init() {
    try {

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("Menu");
                JCheckBoxMenuItem checkBoxMenuItem
                        = new JCheckBoxMenuItem("JCheckBoxMenuItem");
                checkBoxMenuItem.setSelected(true);
                menu.add(checkBoxMenuItem);
                bar.add(menu);
                setJMenuBar(bar);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:bug8031573.java

示例3: getFittingMenubar

import javax.swing.JMenuBar; //导入依赖的package包/类
private void getFittingMenubar(String mode) {
	JMenuBar jmb = new JMenuBar();
	JMenuItem[][] menuItems = { { new JMenuItem(FI_FILE_NEW), null, new JMenuItem(FI_FILE_EXIT) },
			{ new JMenuItem(FI_HELP), null, new JMenuItem(FI_ABOUT) } };
	String[] menuTitles = { "File", "Help" };
	char[] chars = { 'F', 'e' };
	for (int i = 0; i < menuItems.length; i++) {
		JMenu menu = new JMenu(menuTitles[i]);
		menu.setMnemonic(chars[i]);
		for (int j = 0; j < menuItems[i].length; j++) {
			if (menuItems[i][j] == null) {
				menu.addSeparator();
			} else {
				menu.add(menuItems[i][j]);
				if (i == 0 && (j == 0 && mode.equals("demo"))) {
					menuItems[i][j].setEnabled(false);
				}
			}
		}
		jmb.add(menu);
	}
	setMenuBar(jmb);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:24,代码来源:MainJwatWizard.java

示例4: createAndShowGUI

import javax.swing.JMenuBar; //导入依赖的package包/类
private static void createAndShowGUI(TestItem testItem) {

        frame = new JFrame();
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JMenuBar menuBar = new JMenuBar();
        menu = new JMenu("Menu");
        JMenuItem menuItem = testItem.getMenuItem();
        testItem.setProperties(menuItem);
        menu.add(menuItem);
        menuBar.add(menu);

        frame.setJMenuBar(menuBar);
        frame.setVisible(true);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CloseOnMouseClickPropertyTest.java

示例5: createGUI

import javax.swing.JMenuBar; //导入依赖的package包/类
private static JFrame createGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Some menu");
    menuBar.add(menu);

    for (int i = 0; i < 10; i++) {
        menu.add(new JMenuItem("Some menu #" + i));
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(200, 200));
    frame.setJMenuBar(menuBar);
    return frame;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:bug8071705.java

示例6: drawSelectedComponent

import javax.swing.JMenuBar; //导入依赖的package包/类
private void drawSelectedComponent(Graphics2D g2, JComponent selected, RADComponent rad) {
    if(selected == null) return;
    if(selected.getParent() == null || !selected.getParent().isVisible()) return;
    // draw normal border around toplevel menus
    if (selected instanceof JMenu && selected.getParent() instanceof JMenuBar) {
        JMenuItem menu = (JMenuItem) selected;
        Point location = SwingUtilities.convertPoint(menu, new Point(0, 0), this);
        g2.translate(location.x, location.y);
        // #114610: keep drop rectangle guidelines consistent when menu component is inserted from menu-bar into submenu
        g2.setStroke((currentTargetType == DropTargetType.INTO_SUBMENU) ? DROP_TARGET_LINE_STROKE : SELECTION_STROKE);
        g2.setColor(SELECTION_COLOR);
        g2.drawRect(0, 0, menu.getWidth() - 1, menu.getHeight() - 1);
        g2.translate(-location.x, -location.y);
    }
    
    // style only menuitems and menus that aren't also toplevel menus
    // don't do subrect drawing if doing a drag
    if (selected instanceof JMenuItem && !(selected.getParent() instanceof JMenuBar) && currentTargetComponent == null) {
        JMenuItem item = (JMenuItem) selected;
        drawSubselectedItem(g2, item);
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DropTargetLayer.java

示例7: altPressed

import javax.swing.JMenuBar; //导入依赖的package包/类
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:WindowsRootPaneUI.java

示例8: setDefaultMenuBar

import javax.swing.JMenuBar; //导入依赖的package包/类
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", Float.valueOf(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:_AppMenuBarHandler.java

示例9: start

import javax.swing.JMenuBar; //导入依赖的package包/类
private void start(DropTargetDragEvent dtde) {
    PaletteItem item = PaletteUtils.getSelectedItem();

    if(item != null && !isMenuRelatedComponentClass(item.getComponentClass())) {
        hideMenuLayer();
        return;
    }

    if(formDesigner.getDesignerMode() == FormDesigner.MODE_ADD && item != null) {
        if(JMenuBar.class.isAssignableFrom(item.getComponentClass())) {
            hideMenuLayer();
            return;
        }
        dragop.start(item,dtde.getLocation());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MenuEditLayer.java

示例10: getMenuBarArrayList

import javax.swing.JMenuBar; //导入依赖的package包/类
/** Get MenuBar and tranfer it to ArrayList.
     * @param menu menu to be tranfered
     * @return tranfered menubar */
    private static List<NbMenu> getMenuBarArrayList(JMenuBar menu) {
        visitMenuBar(menu);

        MenuElement [] elements = menu.getSubElements();

        List<NbMenu> list = new ArrayList<NbMenu>();
        for(int k=0; k < elements.length; k++) {
//            if(elements[k] instanceof JMenuItem) {
//                list.add(new NbMenu((JMenuItem)elements[k], null));
                JMenuBarOperator menuOp = new JMenuBarOperator(menu);
                JMenu item = menuOp.getMenu(k);
                list.add(new NbMenu(item, getMenuArrayList(item)));
//            }
            /*if(elements[k] instanceof JMenuBar) {
                JMenuBarOperator menuOp = new JMenuBarOperator(menu);
                list.add(getMenuArrayList(menuOp.getMenu(0)));
            }
             */
        }
        return list;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:MenuChecker.java

示例11: visitMenuBar

import javax.swing.JMenuBar; //导入依赖的package包/类
/** Open all menus in menubar
 * @param menu  to be visited */
public static void visitMenuBar(JMenuBar menu) {
    MenuElement[] elements = menu.getSubElements();

    JMenuBarOperator op = new JMenuBarOperator(menu);

    for (int k = 0; k < elements.length; k++) {
        if (elements[k] instanceof JMenuItem) {
            op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true);
            try {
                op.wait(200);
            } catch (Exception e) {
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:MenuChecker.java

示例12: getMenuBarArrayList

import javax.swing.JMenuBar; //导入依赖的package包/类
/** Get MenuBar and tranfer it to ArrayList.
    * @param menu menu to be tranfered
    * @return tranfered menubar  - !separator is ignored
    */
   public static ArrayList<NbMenuItem> getMenuBarArrayList(JMenuBar menu) {
//       System.out.println("getMenuBarArrayList " + menu.getName());
       visitMenuBar(menu);

       MenuElement[] elements = menu.getSubElements();

       ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
       for (int k = 0; k < elements.length; k++) {
           if (elements[k] instanceof JPopupMenu.Separator) {
               NbMenuItem separator = new NbMenuItem();
               separator.setSeparator(true);
               list.add(separator);
           } else {
               if (elements[k] instanceof JMenuItem) {

                   NbMenuItem item = new NbMenuItem((JMenuItem) elements[k]);
                   JMenuBarOperator menuOp = new JMenuBarOperator(menu);
                   item.setSubmenu(getMenuArrayList(menuOp.getMenu(k)));
                   list.add(item);
               }
           }
       }
       return list;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:MenuChecker.java

示例13: getTrafficMenubar

import javax.swing.JMenuBar; //导入依赖的package包/类
private void getTrafficMenubar() {
	JMenuBar jmb = new JMenuBar();
	JMenuItem[][] menuItems = { { new JMenuItem(TR_FILE_NEW), null, new JMenuItem(TR_FILE_EXIT) },
			{ new JMenuItem(TR_HELP), null, new JMenuItem(TR_ABOUT) } };
	String[] menuTitles = { "File", "Help" };
	char[] chars = { 'F', 'e' };
	for (int i = 0; i < menuItems.length; i++) {
		JMenu menu = new JMenu(menuTitles[i]);
		menu.setMnemonic(chars[i]);
		for (int j = 0; j < menuItems[i].length; j++) {
			if (menuItems[i][j] == null) {
				menu.addSeparator();
			} else {
				menu.add(menuItems[i][j]);
			}
		}
		jmb.add(menu);
	}
	setMenuBar(jmb);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:21,代码来源:MainJwatWizard.java

示例14: makeMenubar

import javax.swing.JMenuBar; //导入依赖的package包/类
/**
 * Creates workload analysis menu
 * @return menu
 */
public void makeMenubar() {
	workloadMenubar = new JMenuBar();
	JMenuItem[][] menuItems = { { new JMenuItem(HELP),null,new JMenuItem(HELP_CREDITS) } };
	String[] menuTitles = { "Help" };
	char[] chars = { 'e' };
	for (int i = 0; i < menuItems.length; i++) {
		JMenu menu = new JMenu(menuTitles[i]);
		menu.setMnemonic(chars[i]);
		for (int j = 0; j < menuItems[i].length; j++) {
			if (menuItems[i][j] == null) {
				menu.addSeparator();
			} else {
				menu.add(menuItems[i][j]);
			}
		}
		workloadMenubar.add(menu);
	}
	parent.setMenuBar(workloadMenubar);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:24,代码来源:JWatMainPanel.java

示例15: InputFrame

import javax.swing.JMenuBar; //导入依赖的package包/类
public InputFrame(){
    panel = new InputPanel(254);
    Container c = this.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(new JScrollPane(panel), BorderLayout.CENTER);
    JButton jb = new JButton("Transfer");
    
    //add menu bar
    JMenuBar jmb = new JMenuBar();
    JMenu menu = new JMenu("File");
    jmb.add(menu);
    
    initMenuItems(); //! da drin schreiben (und im InputPanel)
    
    menu.add(miSave);
    menu.add(miSaveAs);
    menu.add(miLoad);
    menu.addSeparator(); //! ...trennstrich im menü, dann dein item
    menu.add(miExport);
    this.setJMenuBar(jmb);
}
 
开发者ID:sachsenschnitzel,项目名称:DBan-Config-Generator,代码行数:22,代码来源:InputFrame.java


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