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