javax.swing.JMenuBar类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中javax.swing.JMenuBar类的一些代码示例,展示了JMenuBar类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuBar类的具体详情如下:
包路径:javax.swing.JMenuBar
类名称:JMenuBar

JMenuBar介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
   new JMenuItem("Screenshot");
  screenshot.setAccelerator(
   KeyStroke.getKeyStroke(
    KeyEvent.VK_0,
    public void actionPerformed(ActionEvent ae) {
     BufferedImage img = getScreenShot(
      f.getContentPane() );
     JOptionPane.showMessageDialog(
      null,
  JMenu menu = new JMenu("Other");
  menu.add(screenshot);
  JMenuBar mb = new JMenuBar();
  mb.add(menu);
  f.setJMenuBar(mb);
  p.add( new JScrollPane(new JTree()),
   BorderLayout.WEST );
  p.add( new JScrollPane( new JTextArea(HELP,10,30) ),
   BorderLayout.CENTER );

代码示例来源:origin: log4j/log4j

/**
 * Removes old file list and creates a new file list
 * with the updated MRU list.
 */
protected void updateMRUList() {
 JMenu menu = _logMonitorFrame.getJMenuBar().getMenu(0);
 menu.removeAll();
 menu.add(createOpenMI());
 menu.add(createOpenURLMI());
 menu.addSeparator();
 menu.add(createCloseMI());
 createMRUFileListMI(menu);
 menu.addSeparator();
 menu.add(createExitMI());
}

代码示例来源:origin: groovy/groovy-core

/**
 * Provide the standard Groovy <code>size()</code> method for <code>JMenuBar</code>.
 *
 * @param self a JMenuBar
 * @return the menu count of the menuBar
 * @since 1.6.4
 */
public static int size(JMenuBar self) {
  return self.getMenuCount();
}

代码示例来源:origin: log4j/log4j

protected JMenuBar createMenuBar() {
 JMenuBar menuBar = new JMenuBar();
 menuBar.add(createFileMenu());
 menuBar.add(createEditMenu());
 menuBar.add(createLogLevelMenu());
 menuBar.add(createViewMenu());
 menuBar.add(createConfigureMenu());
 menuBar.add(createHelpMenu());
 return (menuBar);
}

代码示例来源:origin: kevin-wayne/algs4

private static JMenuBar createMenuBar() {
  JMenuBar menuBar = new JMenuBar();
  JMenu menu = new JMenu("File");
  menuBar.add(menu);
  JMenuItem menuItem1 = new JMenuItem(" Save...   ");
  menuItem1.addActionListener(std);
  menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
              Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
  menu.add(menuItem1);
  return menuBar;
}

代码示例来源:origin: libgdx/libgdx

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);

代码示例来源:origin: pmd/pmd

public GUI() {
  frame = new JFrame("PMD Duplicate Code Detector (v " + PMDVersion.VERSION + ')');
  JMenu fileMenu = new JMenu("File");
  fileMenu.setMnemonic('f');
  JMenuItem exitItem = new JMenuItem("Exit");
  exitItem.setMnemonic('x');
  exitItem.addActionListener(new CancelListener());
  fileMenu.add(exitItem);
  JMenu viewMenu = new JMenu("View");
  fileMenu.setMnemonic('v');
  viewMenu.add(trimItem);
  JMenuBar menuBar = new JMenuBar();
  menuBar.add(fileMenu);
  menuBar.add(viewMenu);
  frame.setJMenuBar(menuBar);
  frame.getContentPane().setLayout(new BorderLayout());
  JPanel topPanel = new JPanel();
  topPanel.setLayout(new BorderLayout());
  topPanel.add(progressPanel, BorderLayout.CENTER);
  setProgressControls(false); // not running now
  frame.getContentPane().add(topPanel, BorderLayout.NORTH);
  frame.getContentPane().add(resultsPanel, BorderLayout.CENTER);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();

代码示例来源:origin: kevin-wayne/algs4

/**
 * Displays the picture in a window on the screen.
 */
public void show() {
  // create the GUI for viewing the image if needed
  if (frame == null) {
    frame = new JFrame();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);
    JMenuItem menuItem1 = new JMenuItem(" Save...   ");
    menuItem1.addActionListener(this);
    // use getMenuShortcutKeyMaskEx() in Java 10 (getMenuShortcutKeyMask() deprecated)           
    menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(menuItem1);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(getJLabel());
    // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    if (filename == null) frame.setTitle(width + "-by-" + height);
    else                  frame.setTitle(filename);
    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
  // draw
  frame.repaint();
}

代码示例来源:origin: marytts/marytts

jLabel_MessageBarIcon = new javax.swing.JLabel();
jButton_Display = new javax.swing.JButton();
jMenuBar_AdminWindow = new javax.swing.JMenuBar();
jMenu_File = new javax.swing.JMenu();
jMenuItem_Open = new javax.swing.JMenuItem();
jMenuItem_ImportText = new javax.swing.JMenuItem();
jSeparator_File = new javax.swing.JSeparator();
jMenuItem_Exit = new javax.swing.JMenuItem();
jMenu_Tools = new javax.swing.JMenu();
jMenuItem_Options = new javax.swing.JMenuItem();
jMenu_Window = new javax.swing.JMenu();
jCheckBoxMenuItem_AdminWindow = new javax.swing.JCheckBoxMenuItem();
jCheckBoxMenuItem_SpeakerWindow = new javax.swing.JCheckBoxMenuItem();
jMenu_File.add(jMenuItem_Exit);
jMenuBar_AdminWindow.add(jMenu_File);
jMenu_Tools.setText("Tools");
jMenu_Tools.add(jMenuItem_Options);
jMenuBar_AdminWindow.add(jMenu_Tools);
jMenuBar_AdminWindow.add(jMenu_Window);
jMenuBar_AdminWindow.add(jMenu_Help);

代码示例来源:origin: stackoverflow.com

public void run() {
  JFrame frame = new JFrame("Gabby");
  final JPanel dm = new JPanel() {
  dm.setBorder(BorderFactory.createLineBorder(Color.blue, 10));
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(dm);
  frame.pack();
  frame.setLocationByPlatform(true);
  JMenuBar menuBar = new JMenuBar();
  JMenu fileMenu = new JMenu("File");
  menuBar.add(fileMenu);
  frame.setJMenuBar(menuBar);
  frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100, 100, 500, 500);
contentPanel.setLayout(new MigLayout("insets 4 4 4 4",
    "[fill,30%][fill,40%][fill,30%]", "[fill,grow]"));
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Open");
menu.add(item);
menubar.add(menu);
frame.setJMenuBar(menubar);
contentPanel.add(new JScrollPane());
contentPanel.add(new JScrollPane(new JEditorPane("text/plain", "Hello World")));
contentPanel.add(new JScrollPane());
frame.setContentPane(contentPanel);
frame.setVisible(true);

代码示例来源:origin: stanfordnlp/CoreNLP

private JMenuBar addMenuBar() {
 JMenuBar menubar = new JMenuBar();
 JMenu fileMenu = new JMenu("File");
 menubar.add(fileMenu);
 JMenu editMenu = new JMenu("Edit");
 menubar.add(editMenu);
 JMenu classifierMenu = new JMenu("Classifier");
 menubar.add(classifierMenu);
 JMenuItem openFile = new JMenuItem("Open File");
 openFile.setMnemonic('O');
 openFile.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, menuMask));
 openFile.addActionListener(actor);
 fileMenu.add(openFile);

代码示例来源:origin: stackoverflow.com

JFrame myframe = new JFrame();
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("size");
JMenuItem size = new JMenuItem("size");
menu.add(size);
menubar.add(menu);
myframe.setJMenuBar(menubar);

代码示例来源:origin: stackoverflow.com

menuBar = new JMenuBar(); //menubar
fileM = new JMenu("File"); //file menu
editM = new JMenu("Edit"); //edit menu
viewM = new JMenu("View"); //edit menu
scpane = new JScrollPane(ta); //scrollpane  and add textarea to scrollpane
exitI = new JMenuItem("Exit");
cutI = new JMenuItem("Cut");
copyI = new JMenuItem("Copy");
pasteI = new JMenuItem("Paste");
selectI = new JMenuItem("Select All"); //menuitems
ta.setWrapStyleWord(true);
setJMenuBar(menuBar);
menuBar.add(fileM);
menuBar.add(editM);
menuBar.add(viewM);
fileM.add(saveI);
selectI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
pane.add(scpane,BorderLayout.CENTER);
pane.add(toolBar,BorderLayout.SOUTH);
statusI.addActionListener(this);
setVisible(true);

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame("MenuBar Exampe");
JMenuItem barItem = new JMenuItem(new AbstractAction("Bar") {
JMenu fooMenu = new JMenu("Foo");
fooMenu.add(barItem);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fooMenu);
menuBarHoldingPanel.add(menuBar, BorderLayout.PAGE_START);
mainPanel.add(Box.createRigidArea(new Dimension(400, 150)));
mainPanel.add(menuBarHoldingPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

代码示例来源:origin: IanDarwin/javasrc

public MacOsUiHints( ) {
    jf = new JFrame("MacOsUiHints");
    JButton button = new JButton("Exit");
    button.addActionListener(new ActionListener( ) {
      public void actionPerformed(ActionEvent arg0) {
        System.exit(0);
      }
    });
    jf.getContentPane( ).add(button);
    
    JMenuBar mb = new JMenuBar();
    jf.setJMenuBar(mb);
    
    JMenu fileMenu = new JMenu("File");
    mb.add(fileMenu);
    fileMenu.add(new JMenuItem("Quit"));
    
    mb.add(new JMenu("Edit"));
    
    // Tester: see that Application->About produces our popup
    // Ditto for Preferences and Shutdown.
    // MacOSAppAdapter adapter =
    //   new MacOSAppAdapter(jf, abouter, prefser, printer, shutter);
    //adapter.register( );
    jf.setSize(300, 200);

  }
}

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.addMouseListener(new MouseAdapter() {
  public void mouseDragged(MouseEvent e) {
    Point p = frame.getLocation();
    frame.setLocation(p.x + e.getX() - point.x,
        p.y + e.getY() - point.y);
frame.setSize(300, 300);
frame.setLocation(200, 200);
frame.setLayout(new BorderLayout());
frame.getContentPane().add(new JLabel("Drag to move", JLabel.CENTER),
    BorderLayout.CENTER);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
menuBar.add(menu);
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new ActionListener(){
  @Override
menu.add(item);
frame.setJMenuBar(menuBar);

代码示例来源:origin: stackoverflow.com

JMenuBar menuBar = new JMenuBar();
menuBar.add(createMenu("Menu 1"));
menuBar.add(createMenu("Menu 2"));
menuBar.add(createMenu("Menu 3"));
menuBar.add(new JSeparator());
menuBar.add(new JButton("   Seach ....  "));
menuBar.add(new JTextField("   Seach ....  "));
menuBar.add(new JComboBox(new Object[]{"height", "length", "volume"}));
menuBar.add(Box.createHorizontalGlue());
menuBar.add(createMenu("About"));
JFrame frame = new JFrame("MenuGlueDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(menuBar);
frame.pack();
frame.setVisible(true);
JMenu m = new JMenu(title);
m.add("Menu item #1 in " + title);
m.add("Menu item #2 in " + title);
m.add("Menu item #3 in " + title);
if (title.equals("About")) {

代码示例来源:origin: stackoverflow.com

JMenu menu = new JMenu("Menu");

JMenuItem item = new JMenuItem("Add");
item.add(new JButton("SOMETHING A BIT WORDY"));
item.setLayout(new FlowLayout()); // set FlowLayout for item
item.setPreferredSize(new Dimension(200, 100)); // hard code implementation :-(
menu.add(item);

// ... 
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
JFrame frame = new JFrame();
frame.setJMenuBar(menuBar);

// ...
frame.pack();
frame.setVisible(true);

代码示例来源:origin: pentaho/mondrian

toolbarPreferencesButton = new javax.swing.JButton();
requireSchemaCheckboxMenuItem = new javax.swing.JCheckBoxMenuItem();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
newMenu = new javax.swing.JMenu();
newSchemaMenuItem = new javax.swing.JMenuItem();
newQueryMenuItem = new javax.swing.JMenuItem();
newJDBCExplorerMenuItem = new javax.swing.JMenuItem();
windowMenu = new javax.swing.JMenu();
getContentPane().add(desktopPane, java.awt.BorderLayout.CENTER);
getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(viewMenu);
menuBar.add(toolsMenu);
menuBar.add(windowMenu);
menuBar.add(helpMenu);

相关文章