本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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));
}
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}