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


Java JMenuBar.add方法代码示例

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


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

示例1: showUI

import javax.swing.JMenuBar; //导入方法依赖的package包/类
private static void showUI() {
    sFrame = new JFrame();
    sFrame.add(new JLabel("Some dummy content"));

    JMenuBar menuBar = new JMenuBar();

    sMenu = new JMenu("Menu");
    JMenuItem item = new JMenuItem("Item");
    sMenu.add(item);

    sMenuItem = new WeakReference<>(item);

    menuBar.add(sMenu);

    sFrame.setJMenuBar(menuBar);

    sFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    sFrame.pack();
    sFrame.setVisible(true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ScreenMenuMemoryLeakTest.java

示例2: setup

import javax.swing.JMenuBar; //导入方法依赖的package包/类
private static void setup(JFrame frame) {
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    // First Menu, F - Mnemonic
    JMenu firstMenu = new JMenu("First Menu");
    firstMenu.setMnemonic(KeyEvent.VK_F);
    firstMenu.add(new JMenuItem("One", KeyEvent.VK_O));
    firstMenu.add(new JMenuItem("Two", KeyEvent.VK_T));
    menuBar.add(firstMenu);

    // Second Menu, S - Mnemonic
    JMenu secondMenu = new JMenu("Second Menu");
    secondMenu.setMnemonic(KeyEvent.VK_S);
    secondMenu.add(new JMenuItem("A Menu Item", KeyEvent.VK_A));
    menuBar.add(secondMenu);

    frame.setSize(350, 250);
    frame.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:bug6921687.java

示例3: 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

示例4: createMenus

import javax.swing.JMenuBar; //导入方法依赖的package包/类
public void createMenus()
{
       JMenu file = new JMenu("File");
       file.add(createMenu("Quit", 0, 0));

	JMenu mode = new JMenu("Timer");
	mode.add(createMenu("Open Comm Port", 0, 0));
	mode.add(createMenu("Show/Hide Dialin", 0, 0));
	mode.add(createMenu("Delete Left Finish", KeyEvent.VK_Z, ActionEvent.ALT_MASK));
	mode.add(createMenu("Delete Right Finish", KeyEvent.VK_SLASH, ActionEvent.ALT_MASK));
       mode.add(createMenu("Set Run Mode", 0, 0));
       mode.add(createMenu("Set Align Mode", 0, 0));
       mode.add(createMenu("Reset", 0, 0));

	JMenu other = new JMenu("Other");
       other.add(createMenu("Show In Progress", 0, 0));
	other.add(createMenu("Show State", 0, 0));
       other.add(createMenu("Hard", 0, 0));
	other.add(createMenu("Simulator", 0, 0));

       JMenuBar bar = new JMenuBar();
       bar.add(file);
	bar.add(mode);
	bar.add(other);
       setJMenuBar(bar);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:27,代码来源:ProSoloInterface.java

示例5: createMenuBar

import javax.swing.JMenuBar; //导入方法依赖的package包/类
/**
 * Set up the menu bar
 */
JMenuBar createMenuBar() {
	JMenuBar menuBar = new JMenuBar();
	// File
	JMenu menuFile = new JMenu(textBundle.get("SwingAppleCommander.MenuFile")); //$NON-NLS-1$
	// File->Open
    JMenuItem openItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileOpen")); //$NON-NLS-1$
    openItem.addActionListener(this);
	menuFile.add(openItem);
	// File->Close
    JMenuItem closeItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileClose")); //$NON-NLS-1$
    closeItem.addActionListener(this);
	menuFile.add(closeItem);
	// File->New
    JMenuItem newItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileNew")); //$NON-NLS-1$
    newItem.addActionListener(this);
	menuFile.add(newItem);
	// File->Exit
    JMenuItem quitItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileQuit")); //$NON-NLS-1$
    quitItem.addActionListener(this);
	menuFile.add(quitItem);
	menuBar.add(menuFile);
	return menuBar;
}
 
开发者ID:AppleCommander,项目名称:AppleCommander,代码行数:27,代码来源:SwingAppleCommander.java

示例6: makeMenubar

import javax.swing.JMenuBar; //导入方法依赖的package包/类
/**
 * Creates workload analysis menu
 * @return menu
 */
public void makeMenubar() {
	workloadMenubar = new JMenuBar();
	JMenuItem[][] menuItems = { { 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:HOMlab,项目名称:QN-ACTR-Release,代码行数:24,代码来源:JWatMainPanel.java

示例7: setNewMenuBar

import javax.swing.JMenuBar; //导入方法依赖的package包/类
private void setNewMenuBar(JMenuBar newMenuBar) {
    JMenuBar oldMenuBar = getJMenuBar();

    if (oldMenuBar == null) {
        setJMenuBar(newMenuBar);
    } else {
        System.out.println("Swapped menus");
        int maxOldMenus = oldMenuBar.getMenuCount();
        int maxNewMenus = newMenuBar.getMenuCount();

        if (maxNewMenus > 0)
            oldMenuBar.add(newMenuBar.getMenu(0));

        for (int i = maxOldMenus - 1; i >= 0; i--) {
            oldMenuBar.remove(i);
        }

        for (int i = 1; i < maxNewMenus; i++) {
            oldMenuBar.add(newMenuBar.getMenu(0));
        }

    }
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:24,代码来源:MysterFrame.java

示例8: makeMenuBar

import javax.swing.JMenuBar; //导入方法依赖的package包/类
public JMenuBar makeMenuBar(JFrame frame) {
    JMenuBar menuBar = new JMenuBar();

    for (int i = 0; i < mysterMenuFactories.size(); i++) {
        menuBar.add(mysterMenuFactories.get(i).makeMenu(frame));
    }

    return menuBar;
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:10,代码来源:MysterMenuBarFactory.java

示例9: initializeMenus

import javax.swing.JMenuBar; //导入方法依赖的package包/类
private void initializeMenus () {
	{
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		{
			JMenu fileMenu = new JMenu();
			menuBar.add(fileMenu);
			fileMenu.setText("File");
			fileMenu.setMnemonic(KeyEvent.VK_F);
			{
				openMenuItem = new JMenuItem("Open Hiero settings file...");
				openMenuItem.setMnemonic(KeyEvent.VK_O);
				openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
				fileMenu.add(openMenuItem);
			}
			{
				saveMenuItem = new JMenuItem("Save Hiero settings file...");
				saveMenuItem.setMnemonic(KeyEvent.VK_S);
				saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
				fileMenu.add(saveMenuItem);
			}
			fileMenu.addSeparator();
			{
				saveBMFontMenuItem = new JMenuItem("Save BMFont files (text)...");
				saveBMFontMenuItem.setMnemonic(KeyEvent.VK_B);
				saveBMFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));
				fileMenu.add(saveBMFontMenuItem);
			}
			fileMenu.addSeparator();
			{
				exitMenuItem = new JMenuItem("Exit");
				exitMenuItem.setMnemonic(KeyEvent.VK_X);
				fileMenu.add(exitMenuItem);
			}
		}
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:38,代码来源:Hiero.java

示例10: createMainMenuBars

import javax.swing.JMenuBar; //导入方法依赖的package包/类
public static JMenuBar createMainMenuBars(List<XML_Menu> menuLayers, List<XML_Menu> menuLayersLocal) {
	JMenuBar mainMenuBar = new JMenuBar();
	for (XML_Menu sub_menu : menuLayers) {
		if ( mapApp.start != null ) {
			mapApp.start.setText("Initializing " + sub_menu.name + " Menu...");
		}
		if ( sub_menu.proj.toLowerCase().indexOf(MapApp.CURRENT_PROJECTION.toLowerCase()) != -1 ) {
			JMenu subMenu = createMenu(sub_menu);
			if (subMenu.getItemCount() != 0)
				mainMenuBar.add(subMenu);
				subMenu.addMenuListener(mapApp.listener);
		}
	}
	// Add My Sessions Menu
	for (XML_Menu sub_menu2 : menuLayersLocal) {
		if ( mapApp.start != null ) {
			mapApp.start.setText("Initializing " + sub_menu2.name + " Menu...");
		}
		if ( sub_menu2.proj.toLowerCase().indexOf(MapApp.CURRENT_PROJECTION.toLowerCase()) != -1 ) {
			JMenu subMenu2 = createMenu(sub_menu2);
			if (subMenu2.getItemCount() != 0)
				mainMenuBar.add(subMenu2);
				subMenu2.addMenuListener(mapApp.listener);
		}
	}

	if ( mapApp != null && mapApp.start != null ) {
		mapApp.start.setText("Initializing GUI");
	}
	return mainMenuBar;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:32,代码来源:XML_Menu.java

示例11: createUI

import javax.swing.JMenuBar; //导入方法依赖的package包/类
private static void createUI() {

        desktopPane = new JDesktopPane();
        frame.getContentPane().add(desktopPane);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        menuBar = new JMenuBar();
        frame.setJMenuBar(menuBar);

        menu = new JMenu("File");
        menuBar.add(menu);

        menuItem = new JMenuItem("New Child");
        menuItem.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JInternalFrame f = new JInternalFrame("Child "
                                + (++count), true, true, true, true);
                        f.setSize(200, 300);
                        f.setLocation(count * 20, count * 20);
                        desktopPane.add(f);
                        f.setVisible(true);
                    }
                });
        menu.add(menuItem);
        frame.setSize(500, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:TestJInternalFrameMinimize.java

示例12: getMenu

import javax.swing.JMenuBar; //导入方法依赖的package包/类
public static JMenuBar getMenu( JFreeChart chart,ApplicationFrame jg ){
Action SaveAs = new SaveAs_Action(chart,"Save as...",null,"Save as...");
Action Quit = new Quit_Action(jg,"Quit",null,"Quit");

    JMenuBar JMB = new JMenuBar();
                
    JMenu file = new JMenu("File");
    JMB.add(file);
    file.add(SaveAs);file.add(Quit);
    return JMB;
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:12,代码来源:AbstractFramePlt.java

示例13: buildMenus

import javax.swing.JMenuBar; //导入方法依赖的package包/类
protected void buildMenus() {
    menuBar = new JMenuBar();
    menuBar.setOpaque(true);
    JMenu file = buildFileMenu();
    JMenu edit = buildEditMenu();
    JMenu views = buildViewsMenu();
    JMenu speed = buildSpeedMenu();
    JMenu help = buildHelpMenu();

    // load a theme from a text file
    MetalTheme myTheme = null;
    try {
        InputStream istream = getClass().getResourceAsStream(
                "/resources/MyTheme.theme");
        myTheme = new PropertiesMetalTheme(istream);
    } catch (NullPointerException e) {
        System.out.println(e);
    }

    // build an array of themes
    MetalTheme[] themes = { new OceanTheme(),
        new DefaultMetalTheme(),
        new GreenMetalTheme(),
        new AquaMetalTheme(),
        new KhakiMetalTheme(),
        new DemoMetalTheme(),
        new ContrastMetalTheme(),
        new BigContrastMetalTheme(),
        myTheme };

    // put the themes in a menu
    JMenu themeMenu = new MetalThemeMenu("Theme", themes);

    menuBar.add(file);
    menuBar.add(edit);
    menuBar.add(views);
    menuBar.add(themeMenu);
    menuBar.add(speed);
    menuBar.add(help);
    setJMenuBar(menuBar);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:MetalworksFrame.java

示例14: buildMenuBar

import javax.swing.JMenuBar; //导入方法依赖的package包/类
/**
 * Builds the menu bar
 * 
 * @return JMenuBar
 */
public JMenuBar buildMenuBar() {
    JMenu file = new JMenu();
    Messages.get().message("file").subscribe((msg) -> {
        file.setText(msg);
    });
    file.add(get(ActionNew.class));
    file.addSeparator();
    file.add(get(ActionOpen.class));
    file.add(buildReopenProjectMenu());
    file.addSeparator();
    file.add(get(ActionSave.class));
    file.add(get(ActionSaveAs.class));
    file.add(get(ActionExport.class));
    JMenu edit = new JMenu();
    Messages.get().message("edit").subscribe((msg) -> {
        edit.setText(msg);
    });
    edit.add(get(ActionCopyNode.class));
    edit.add(get(ActionPasteNode.class));
    edit.addSeparator();
    edit.add(get(ActionDeleteSelectedNodes.class));
    edit.addSeparator();
    edit.add(get(ActionUserPreferences.class));
    JMenu view = new JMenu();
    Messages.get().message("view").subscribe((msg) -> {
        view.setText(msg);
    });
    JMenu rendering = new JMenu();
    Messages.get().message("rendering").subscribe((msg) -> {
        rendering.setText(msg);
    });
    rendering.add(get(ActionSelectWindow.class));
    view.add(rendering);
    JMenu help = new JMenu();
    Messages.get().message("help").subscribe((msg) -> {
        help.setText(msg);
    });
    help.add(get(ActionAboutVisnode.class));
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(file);
    menuBar.add(edit);
    menuBar.add(view);
    menuBar.add(help);
    return menuBar;
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:51,代码来源:Actions.java

示例15: init

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


		butt = new JButton("확인");
		butt.addActionListener(this);

		tf = new JTextField(20);
		tf.addKeyListener(this);

		JPanel base = new JPanel();
		base.setLayout(new BorderLayout());
		JPanel p1 = new JPanel();
		p1.setLayout(new BorderLayout());
		JMenuBar menu = new JMenuBar();
		JMenu file = new JMenu("파일");
		JMenu draw = new JMenu("그리기");
		JMenu color = new JMenu("색상");

		JMenuItem menu1 = new JMenuItem("새그림");
		JMenuItem menu2 = new JMenuItem("열기");
		JMenuItem menu3 = new JMenuItem("저장");
		JMenuItem menu4 = new JMenuItem("종료");
		JMenuItem menu5 = new JMenuItem("사각형");
		JMenuItem menu6 = new JMenuItem("타원");
		JMenuItem menu7 = new JMenuItem("둥근사각형");
		JMenuItem menu8 = new JMenuItem("직선");
		JMenuItem menu9 = new JMenuItem("윤각선");
		JMenuItem menu10 = new JMenuItem("채우기");

		menu1.addActionListener(this);
		menu2.addActionListener(this);
		menu3.addActionListener(this);
		menu4.addActionListener(this);
		menu5.addActionListener(this);
		menu6.addActionListener(this);
		menu7.addActionListener(this);
		menu8.addActionListener(this);
		menu9.addActionListener(this);
		menu10.addActionListener(this);


		menu.add(file);
		file.add(menu1);
		file.add(menu2);
		file.add(menu3);
		file.add(menu4);

		menu.add(draw);
		draw.add(menu5);
		draw.add(menu6);
		draw.add(menu7);
		draw.add(menu8);

		menu.add(color);
		color.add(menu9);
		color.add(menu10);

		p1.add("Center", menu);
		p1.add("East", tf);

		base.add("North", p1);

		panel.add(imageLabel);
		add("North", base);
		add("Center", panel);
		add("South",butt);
		butt.setVisible(false);

	}
 
开发者ID:beargrllys,项目名称:OverTale,代码行数:70,代码来源:DrowLine.java


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