List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:DOMTreeTest.java
public DOMTreeFrame() { setTitle("DOMTreeTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile();//from w w w. j a v a 2s . co m } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); }
From source file:GlassPaneDemo.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*w w w.ja v a 2s . c om*/ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("GlassPaneDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Start creating and adding components. JCheckBox changeButton = new JCheckBox("Glass pane \"visible\""); changeButton.setSelected(false); // Set up the content pane, where the "main GUI" lives. Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(changeButton); contentPane.add(new JButton("Button 1")); contentPane.add(new JButton("Button 2")); // Set up the menu bar, which appears above the content pane. JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); menu.add(new JMenuItem("Do nothing")); menuBar.add(menu); frame.setJMenuBar(menuBar); // Set up the glass pane, which appears over both menu bar // and content pane and is an item listener on the change // button. myGlassPane = new MyGlassPane(changeButton, menuBar, frame.getContentPane()); changeButton.addItemListener(myGlassPane); frame.setGlassPane(myGlassPane); // Show the window. frame.pack(); frame.setVisible(true); }
From source file:ProgressMonitorInputStreamTest.java
public TextFrame() { setTitle("ProgressMonitorInputStreamTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); textArea = new JTextArea(); add(new JScrollPane(textArea)); chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from ww w. j a v a2s . co m*/ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { openFile(); } catch (IOException exception) { exception.printStackTrace(); } } }); fileMenu.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); }
From source file:InternalFrameTest.java
public DesktopFrame() { setTitle("InternalFrameTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); desktop = new JDesktopPane(); add(desktop, BorderLayout.CENTER); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/* w w w . j a v a 2 s . c o m*/ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem openItem = new JMenuItem("New"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { createInternalFrame(new JLabel(new ImageIcon(planets[counter] + ".gif")), planets[counter]); counter = (counter + 1) % planets.length; } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenu windowMenu = new JMenu("Window"); menuBar.add(windowMenu); JMenuItem nextItem = new JMenuItem("Next"); nextItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { selectNextWindow(); } }); windowMenu.add(nextItem); JMenuItem cascadeItem = new JMenuItem("Cascade"); cascadeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { cascadeWindows(); } }); windowMenu.add(cascadeItem); JMenuItem tileItem = new JMenuItem("Tile"); tileItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tileWindows(); } }); windowMenu.add(tileItem); final JCheckBoxMenuItem dragOutlineItem = new JCheckBoxMenuItem("Drag Outline"); dragOutlineItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { desktop.setDragMode(dragOutlineItem.isSelected() ? JDesktopPane.OUTLINE_DRAG_MODE : JDesktopPane.LIVE_DRAG_MODE); } }); windowMenu.add(dragOutlineItem); }
From source file:commonline.query.gui.Frame.java
private void initializeMenu(boolean isMac) { JMenu file = new JMenu("File"); JMenuItem open = new JMenuItem(openAction); JMenuItem clear = new JMenuItem(clearDatabaseAction); JMenuItem exit = new JMenuItem(new ExitAction()); file.add(open);/* w w w . j ava2 s .c o m*/ file.addSeparator(); file.add(clear); if (!isMac) { file.addSeparator(); file.add(exit); } JMenu query = new JMenu("Query"); JMenuItem execute = new JMenuItem(executeScriptAction); JMenuItem stop = new JMenuItem(stopScriptAction); query.add(execute); query.add(stop); JMenuBar menuBar = new JMenuBar(); menuBar.add(file); menuBar.add(query); setJMenuBar(menuBar); }
From source file:ImageIOTest.java
public ImageIOFrame() { setTitle("ImageIOTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile();/*from ww w . ja v a2 s . c o m*/ } }); fileMenu.add(openItem); JMenu saveMenu = new JMenu("Save"); fileMenu.add(saveMenu); Iterator<String> iter = writerFormats.iterator(); while (iter.hasNext()) { final String formatName = iter.next(); JMenuItem formatItem = new JMenuItem(formatName); saveMenu.add(formatItem); formatItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveFile(formatName); } }); } JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); }
From source file:com.egangotri.transliteratorAsSwing.TransliteratorJFrame.java
public TransliteratorJFrame() { super("eGangotri Indic Transliterator"); PrintWriter pw = new PrintWriter(System.out, true); setSize(650, 650);/*from w w w . jav a2s . co m*/ // menubar menubar = new JMenuBar(); // menus file = new JMenu("File"); help = new JMenu("Help"); // JMenuItem save_1 = new JMenuItem("Save Input"); save_1.setActionCommand("save_1"); save_1.addActionListener(this); save_2 = new JMenuItem("Save Output-1"); save_2.setActionCommand("save_2"); save_2.addActionListener(this); save_3 = new JMenuItem("Save Output-2"); save_3.setActionCommand("save_3"); save_3.addActionListener(this); open_1 = new JMenuItem("Open File for Input"); open_1.setActionCommand("open_1"); open_1.addActionListener(this); exitItem = new JMenuItem("Exit"); exitItem.setActionCommand("Exit"); exitItem.addActionListener(this); aboutItem = new JMenuItem("About"); aboutItem.setActionCommand("about_item"); aboutItem.addActionListener(this); itransItem = new JMenuItem("ITRANS " + Constants.ENCODING_SCHEME); itransItem.setActionCommand("itrans_encoding"); itransItem.addActionListener(this); slpItem = new JMenuItem("SLP " + Constants.ENCODING_SCHEME); slpItem.setActionCommand("slp_encoding"); slpItem.addActionListener(this); hkItem = new JMenuItem("Harvard Kyoto " + Constants.ENCODING_SCHEME); hkItem.setActionCommand("hk_encoding"); hkItem.addActionListener(this); velthuisItem = new JMenuItem("Velthuis " + Constants.ENCODING_SCHEME); velthuisItem.setActionCommand("velthuis_encoding"); velthuisItem.addActionListener(this); dvnItem = new JMenuItem("Devanagari " + Constants.ENCODING_SCHEME); dvnItem.setActionCommand("devanagari_encoding"); dvnItem.addActionListener(this); iastItem = new JMenuItem("IAST " + Constants.ENCODING_SCHEME); iastItem.setActionCommand("iast_encoding"); iastItem.addActionListener(this); // add menuitems to menu file.add(open_1); file.add(save_1); file.add(save_2); file.add(save_3); file.add(exitItem); help.add(aboutItem); help.add(itransItem); help.add(slpItem); help.add(hkItem); help.add(velthuisItem); help.add(dvnItem); help.add(iastItem); // add menus to menubar menubar.add(file); menubar.add(help); // menus end // JPanel Initilization p1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); p1a = new JPanel(new BorderLayout()); p2 = new JPanel(); p3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); p3a = new JPanel(new BorderLayout()); p4 = new JPanel(); p5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); p5a = new JPanel(new BorderLayout()); p6 = new JPanel(); p6a = new JPanel(); p7 = new JPanel(); // JLabel Initialization label1 = new JLabel("Input:"); label2 = new JLabel("Output-1"); label3 = new JLabel("Output-2"); capitalize = new JCheckBox("Capitalize Extended Latin"); capitalize.setSelected(capitalizeIAST); capitalize.setActionCommand("capitalize"); capitalize.addActionListener(this); // Buttons clearButton = new JButton("Clear"); clearButton.setActionCommand("clear"); clearButton.setToolTipText("Clear all Fields"); refreshButton = new JButton("Refresh"); refreshButton.setActionCommand("refresh"); refreshButton.setToolTipText("Refesh the View"); exitButton = new JButton("Exit"); exitButton.setActionCommand("Exit"); exitButton.setToolTipText("Quit the Application."); clipboardButton1 = new JButton("Clipboard"); clipboardButton1.setActionCommand("clipboard-1"); clipboardButton1.setToolTipText("Clipboard Input"); clipboardButton2 = new JButton("Clipboard"); clipboardButton2.setActionCommand("clipboard-2"); clipboardButton2.setToolTipText("Clipboard Output-1"); clipboardButton3 = new JButton("Clipboard"); clipboardButton3.setActionCommand("clipboard-3"); clipboardButton3.setToolTipText("Clipboard Output-2"); clearButton.addActionListener(this); refreshButton.addActionListener(this); exitButton.addActionListener(this); clipboardButton1.addActionListener(this); clipboardButton2.addActionListener(this); clipboardButton3.addActionListener(this); Container contentPane = getContentPane(); // JTextBox tb1 = new JTextArea(new PlainDocument(), null, 6, 45); tb1.setLineWrap(true); tb1.setWrapStyleWord(true); tb1.addKeyListener(this); tb2 = new JTextArea(new PlainDocument(), null, 6, 45); tb2.setLineWrap(true); tb2.setWrapStyleWord(true); tb2.addKeyListener(this); tb3 = new JTextArea(new PlainDocument(), null, 6, 45); tb3.setLineWrap(true); tb3.setWrapStyleWord(true); tb3.addKeyListener(this); // Setting Fonts Font unicodeFont = new Font(Constants.ARIAL_UNICODE_MS, Font.PLAIN, Constants.FONT_SIZE); tb1.setFont(unicodeFont); tb2.setFont(unicodeFont); tb3.setFont(unicodeFont); comboBox1 = new JComboBox(Constants.ENCODINGS.toArray()); comboBox1.setActionCommand("comboBox1"); comboBox1.setSelectedItem(Constants.ITRANS); comboBox1.addActionListener(this); comboBox2 = new JComboBox(Constants.ENCODINGS.toArray()); comboBox2.setActionCommand("comboBox2"); comboBox2.setSelectedItem(Constants.UNICODE_DVN); comboBox2.addActionListener(this); comboBox3 = new JComboBox(Constants.ENCODINGS.toArray()); comboBox3.setActionCommand("comboBox3"); comboBox3.setSelectedItem(Constants.IAST); comboBox3.addActionListener(this); /** *EXPERIMENT*** */ textPane = new JTextPane(); RTFEditorKit rtfkit = new RTFEditorKit(); // HTMLEditorKit htmlkit = new HTMLEditorKit(); textPane.setEditorKit(rtfkit); // set Kit which will read RTF Doc // textPane.setEditorKit(htmlkit); textPane.setEditable(false); // make uneditable textPane.setPreferredSize(new Dimension(200, 200)); textPane.setText(""); // set p1.add(label1); p1a.add(comboBox1, BorderLayout.LINE_END); p1a.add(clipboardButton1, BorderLayout.LINE_START); p2.add(new JScrollPane(tb1)); p3.add(label2); p3a.add(comboBox2, BorderLayout.LINE_END); p3a.add(clipboardButton2, BorderLayout.LINE_START); p4.add(new JScrollPane(tb2)); p5.add(label3); p5a.add(comboBox3, BorderLayout.LINE_END); p5a.add(clipboardButton3, BorderLayout.LINE_START); p6.add(new JScrollPane(tb3)); p6a.add(capitalize); p7.add(clearButton); p7.add(refreshButton); p7.add(exitButton); this.setJMenuBar(menubar); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(p1); contentPane.add(p1a); contentPane.add(p2); contentPane.add(p3); contentPane.add(p3a); contentPane.add(p4); contentPane.add(p5); contentPane.add(p5a); contentPane.add(p6); contentPane.add(p6a); contentPane.add(p7); }
From source file:StocksTable5.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu mFile = new JMenu("File"); mFile.setMnemonic('f'); JMenuItem mData = new JMenuItem("Retrieve Data..."); mData.setMnemonic('r'); ActionListener lstData = new ActionListener() { public void actionPerformed(ActionEvent e) { retrieveData();// w w w . jav a2s. c o m } }; mData.addActionListener(lstData); mFile.add(mData); mFile.addSeparator(); JMenuItem mExit = new JMenuItem("Exit"); mExit.setMnemonic('x'); ActionListener lstExit = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; mExit.addActionListener(lstExit); mFile.add(mExit); menuBar.add(mFile); return menuBar; }
From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java
private void createMenuBarItem(JMenuBar menuBar, MenuItem item) { String caption = menuConfig.getItemCaption(item.getId()); if (!item.getChildren().isEmpty() || item.isMenu()) { final JMenu jMenu = new JMenu(caption); jMenu.addMenuListener(new MenuListener() { @Override//from w w w. ja v a 2 s . c om public void menuSelected(MenuEvent e) { jMenu.requestFocus(); } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); jMenu.setName(item.getId()); menuBar.add(jMenu); createSubMenu(jMenu, item); } else { JMenuItem jMenuItem = new JMenuItem(caption); jMenuItem.setName(item.getId()); //todo remove hardcoded border jMenuItem.setBorder(BorderFactory.createEmptyBorder(1, 4, 2, 4)); assignShortcut(jMenuItem, item); jMenuItem.setMaximumSize( new Dimension(jMenuItem.getPreferredSize().width, jMenuItem.getMaximumSize().height)); assignCommand(jMenuItem, item); menuBar.add(jMenuItem); } }
From source file:com.planetmayo.debrief.satc.util.StraightLineCullingTestForm.java
private void createMenu() { JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Load") { private static final long serialVersionUID = 1L; @Override//from w ww . j a v a 2 s . c om public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(StraightLineCullingTestForm.this) == JFileChooser.APPROVE_OPTION) { try { loadFile(fc.getSelectedFile()); } catch (IOException ex) { } } } }); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); setJMenuBar(menuBar); }