本文整理了Java中javax.swing.JFrame.setJMenuBar()
方法的一些代码示例,展示了JFrame.setJMenuBar()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.setJMenuBar()
方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:setJMenuBar
暂无
代码示例来源: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: net.sf.tinylaf/tinylaf
private void createMenuBar() {
JMenuBar menuBar = new JMenuBar();
menuBar.add(createFileMenu());
menuBar.add(createEditMenu());
menuBar.add(createThemesMenu());
menuBar.add(createDialogsMenu());
menuBar.add(createMagnifierMenu());
menuBar.add(createDisabledMenu());
menuBar.add(createTestMenu());
menuBar.add(createHelpMenu());
menuBar.add(createRightToLeftMenu());
menus[7] = menuBar;
theFrame.setJMenuBar(menuBar);
}
代码示例来源: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: jMonkeyEngine/jmonkeyengine
private static void createMenu(){
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu menuTortureMethods = new JMenu("Canvas Torture Methods");
menuBar.add(menuTortureMethods);
menuTortureMethods.add(itemRemoveCanvas);
itemRemoveCanvas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
menuTortureMethods.add(itemHideCanvas);
itemHideCanvas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
menuTortureMethods.add(itemSwitchTab);
itemSwitchTab.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
代码示例来源:origin: stackoverflow.com
JMenu menu = new JMenu("Other");
menu.add(screenshot);
JMenuBar mb = new JMenuBar();
mb.add(menu);
f.setJMenuBar(mb);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
代码示例来源:origin: pmd/pmd
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic('f');
exitItem.setMnemonic('x');
exitItem.addActionListener(new CancelListener());
fileMenu.add(exitItem);
JMenu viewMenu = new JMenu("View");
fileMenu.setMnemonic('v');
JMenuItem trimItem = new JCheckBoxMenuItem("Trim leading whitespace");
viewMenu.add(trimItem);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
menuBar.add(viewMenu);
frame.setJMenuBar(menuBar);
frame.getContentPane().add(topPanel, BorderLayout.NORTH);
frame.getContentPane().add(resultsPanel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
代码示例来源:origin: cmusphinx/sphinx4
private static void createMenuBar(JFrame jframe) {
JMenuBar menuBar = new JMenuBar();
jframe.setJMenuBar(menuBar);
JMenu menu = new JMenu("File");
menuBar.add(menu);
menu.add(menuItem);
menu.add(saveMenuItem);
menu.add(menuItem);
menu = new JMenu("Edit");
menuBar.add(menu);
menu = new JMenu("View");
menuBar.add(menu);
代码示例来源:origin: stackoverflow.com
File[] files = userDir.listFiles();
JMenu menu = new JMenu("Recent Files");
JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
JLabel label = new JLabel(" ", JLabel.CENTER);
if (f.isFile() && !f.isHidden()) {
RecentFile rf = new RecentFile(f, label);
menu.add(new JMenuItem(rf.getAction()));
toolBar.add(rf.getAction());
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
f.setJMenuBar(menuBar);
f.add(toolBar, BorderLayout.CENTER);
f.add(label, BorderLayout.SOUTH);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
代码示例来源:origin: apache/geode
private void createMenu() {
JMenuBar menuBar = new JMenuBar();
JMenu sequenceMenu = new JMenu("Sequence");
sequenceMenu.setMnemonic(KeyEvent.VK_S);
sequenceMenu.getAccessibleContext()
.setAccessibleDescription("The only menu in this program that has menu items");
menuBar.add(sequenceMenu);
JMenuItem selectGraphs = new JMenuItem("Choose Graphs", KeyEvent.VK_G);
selectGraphs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.ALT_MASK));
selectGraphs.getAccessibleContext().setAccessibleDescription("Select what graphs to display");
selectGraphs.setActionCommand("selectgraphs");
selectGraphs.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showGraphSelector();
}
});
sequenceMenu.add(selectGraphs);
frame.setJMenuBar(menuBar);
}
代码示例来源:origin: wiztools/rest-client
private void createMenu(){
JMenu jm_file = new JMenu("File");
jm_file.setMnemonic(KeyEvent.VK_F);
jm_file.add(jmi_open_req);
jm_file.add(jmi_open_res);
jm_file.add(jmi_open_archive);
final JMenu jm_open_recent = new JMenu("Open recent");
jm_open_recent.addMenuListener(new MenuListener() {
JMenu jm_edit = new JMenu("Edit");
jm_edit.setMnemonic(KeyEvent.VK_E);
JMenuBar jmb = new JMenuBar();
jmb.add(jm_file);
jmb.add(jm_edit);
jmb.add(jm_history);
jmb.add(jm_tools);
jmb.add(jm_help);
frame.setJMenuBar(jmb);
代码示例来源:origin: stackoverflow.com
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
BufferedImage image = ImageIO.read(new URL("http://pscode.org/media/stromlo1.jpg"));
menu.setHorizontalTextPosition(SwingConstants.CENTER);
menu.setVerticalTextPosition(SwingConstants.BOTTOM);
menu.setIcon(new ImageIcon(image));
menuBar.add(menu);
menu.add(item);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(menuBar);
frame.setSize(500, 550);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
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
setSize(600, 600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
ta.setWrapStyleWord(true);
setJMenuBar(menuBar);
menuBar.add(fileM);
menuBar.add(editM);
menuBar.add(viewM);
fileM.add(saveI);
fileM.add(loadI);
fileM.add(exitI);
editM.add(cutI);
statusI.addActionListener(this);
setVisible(true);
代码示例来源:origin: stackoverflow.com
private JMenuBar menuBar = new JMenuBar();
private JMenu fileMenu = new JMenu();
private StatusBar statusBar = new StatusBar();
private ViewDisplayText displayText = new ViewDisplayText();
menuBar.add(fileMenu);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(displayText.getMainComponent(), BorderLayout.CENTER);
frame.getContentPane().add(statusBar.getComponent(), BorderLayout.PAGE_END);
frame.setJMenuBar(menuBar);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public void setOpenFileAction(Action action) {
displayText.setOpenFileButtonAction(action);
fileMenu.add(new JMenuItem(action));
public void setSaveToFileAction(Action action) {
displayText.setSaveToFileAction(action);
fileMenu.add(new JMenuItem(action));
public void setExitAction(Action exitAction) {
displayText.setExitAction(exitAction);
fileMenu.add(new JMenuItem(exitAction));
代码示例来源:origin: camunda/camunda-bpm-platform
final JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
final JMenu menu = new JMenu("File");
menuBar.add(menu);
menu.add(loadMenuItem);
loadMenuItem.addActionListener(lxa);
} catch (NoClassDefFoundError e) {
menu.add(exitMenuItem);
exitMenuItem.addActionListener(ExitAction.INSTANCE);
代码示例来源:origin: stackoverflow.com
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(createMenuBar());
frame.setVisible(true);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Frame");
menu.setMnemonic(KeyEvent.VK_N);
JMenuItem menuItem = new JMenuItem("New IFrame");
menu.add(menuItem);
menuBar.add(menu);
return menuBar;
代码示例来源:origin: stackoverflow.com
ShowDialog = new JMenuItem(" Show Dialog ");
ShowDialog.addActionListener(showingDialog());
File = new JMenu(" File ");
File.add(Exit);
File.add(ShowDialog);
MenuBar = new JMenuBar();
MenuBar.add(File);
frame.addWindowListener(exitListener);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setJMenuBar(MenuBar);
frame.setPreferredSize(new Dimension(400, 300));
frame.setLocation(100, 100);
frame.pack();
frame.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
代码示例来源: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
public final class Application{
static JFrame mainFrame; //static attribute
public static void start(){
//Empty screen with menu
SwingUtilities.invokeAndWait(() -> {
JFrame frame = new JFrame("Main frame");
mainFrame = frame; //Storing in static attribute
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Start");
menuBar.add(menu);
frame.setJMenuBar(menuBar);
});
}
}
代码示例来源:origin: stackoverflow.com
public class MyProgram {
JFrame frame;
public MyProgram() {
...
frame = new JFrame();
JMenuBar mainMenu = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.add(new JMenuItem("Open..."));
mainMenu.add(fileMenu); // adds a single JMenu to the menubar
frame.setJMenuBar(mainMenu); // adds the entire menubar to the window
...
frame.setVisible();
...
}
内容来源于网络,如有侵权,请联系作者删除!