List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. From source file:MenuActionExample.java
public MenuActionExample() { super(true);// w w w . j a v a 2 s . c om // Create a menu bar and give it a bevel border. menuBar = new JMenuBar(); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); // Create a menu and add it to the menu bar. JMenu menu = new JMenu("Menu"); menuBar.add(menu); // Create a toolbar and give it an etched border. toolBar = new JToolBar(); toolBar.setBorder(new EtchedBorder()); // Instantiate a sample action with the NAME property of // "Download" and the appropriate SMALL_ICON property. SampleAction exampleAction = new SampleAction("Download", new ImageIcon("action.gif")); // Finally, add the sample action to the menu and the toolbar. // These methods are no longer preferred: // menu.add(exampleAction); // toolBar.add(exampleAction); // Instead, you should create actual menu items and buttons: JMenuItem exampleItem = new JMenuItem(exampleAction); JButton exampleButton = new JButton(exampleAction); menu.add(exampleItem); toolBar.add(exampleButton); }
From source file:Interface.Teste.java
public void criacao() { DefaultCategoryDataset ds = new DefaultCategoryDataset(); ds.addValue(40.5, "maximo", "dia 1"); ds.addValue(38.2, "maximo", "dia 2"); ds.addValue(37.3, "maximo", "dia 3"); ds.addValue(31.5, "maximo", "dia 4"); ds.addValue(35.7, "maximo", "dia 5"); ds.addValue(42.5, "maximo", "dia 6"); // cria o grfico JFreeChart grafico = ChartFactory.createLineChart("Meu Grafico", "Dia", "Valor", ds, PlotOrientation.VERTICAL, true, true, false); try {//from w ww . j ava 2 s .c o m OutputStream arquivo = new FileOutputStream("grafico.png"); ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400); arquivo.close(); } catch (Exception e) { e.printStackTrace(); } JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("1")); pop.add(new JMenuItem("2")); pop.add(new JMenuItem("3")); pop.add(new JMenuItem("4")); JPanel painel = new JPanel(); JButton botao = new JButton("teste"); JCalendar cal = new JCalendar(); botao.add(pop); painel.add(cal); painel.add(new ChartPanel(grafico)); //Calendar c = cal.getDate(); Date data = cal.getDate(); int dia = data.getDay(); System.out.println("" + dia); add(painel); }
From source file:net.sf.jabref.gui.worker.MarkEntriesAction.java
public MarkEntriesAction(JabRefFrame frame, int level) { this.frame = frame; this.level = level; //menuItem = new JMenuItem(Globals.menuTitle("Mark entries").replace("&","")); menuItem = new JMenuItem(Localization.lang("Level") + " " + level + " "); menuItem.setMnemonic(String.valueOf(level + 1).charAt(0)); menuItem.setBackground(Globals.prefs.getColor(JabRefPreferences.MARKED_ENTRY_BACKGROUND + this.level)); menuItem.setOpaque(true);/*from w ww.j a v a2 s. c o m*/ menuItem.addActionListener(this); }
From source file:MenuDemo.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu menuFile = new JMenu("File"); menuFile.setMnemonic('f'); JMenuItem menuItem = new JMenuItem("New"); menuItem.setIcon(new ImageIcon("file_new.gif")); menuItem.setMnemonic('n'); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("New"); }/*from ww w . ja v a2 s.co m*/ }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuItem = new JMenuItem("Open..."); menuItem.setIcon(new ImageIcon("file_open.gif")); menuItem.setMnemonic('o'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuDemo.this.repaint(); if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION) return; System.out.println(fileChooser.getSelectedFile()); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuItem = new JMenuItem("Save..."); menuItem.setIcon(new ImageIcon("file_save.gif")); menuItem.setMnemonic('s'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Save..."); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuFile.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.setMnemonic('x'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuBar.add(menuFile); ActionListener fontListener = new ActionListener() { public void actionPerformed(ActionEvent e) { updateMonitor(); } }; JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); menus = new JMenuItem[FontNames.length]; for (int i = 0; i < FontNames.length; i++) { int m = i + 1; menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]); boolean selected = (i == 0); menus[i].setSelected(selected); menus[i].setMnemonic('1' + i); menus[i].setFont(fontArray[i]); menus[i].addActionListener(fontListener); group.add(menus[i]); mFont.add(menus[i]); } mFont.addSeparator(); boldMenuItem = new JCheckBoxMenuItem("Bold"); boldMenuItem.setMnemonic('b'); Font fn = fontArray[1].deriveFont(Font.BOLD); boldMenuItem.setFont(fn); boldMenuItem.setSelected(false); boldMenuItem.addActionListener(fontListener); mFont.add(boldMenuItem); italicMenuItem = new JCheckBoxMenuItem("Italic"); italicMenuItem.setMnemonic('i'); fn = fontArray[1].deriveFont(Font.ITALIC); italicMenuItem.setFont(fn); italicMenuItem.setSelected(false); italicMenuItem.addActionListener(fontListener); mFont.add(italicMenuItem); menuBar.add(mFont); return menuBar; }
From source file:com.db2eshop.gui.component.tab.menu.TabRightClickPopupMenu.java
/** * <p>Constructor for TabRightClickPopupMenu.</p> *///from w w w .j a va2 s . c om public TabRightClickPopupMenu() { add = new JMenuItem("Add Entity"); this.add(add); this.pack(); }
From source file:SimpleMenu.java
/** The convenience method that creates menu panes */ public static JMenu create(ResourceBundle bundle, String menuname, String[] itemnames, ActionListener listener) { // Get the menu title from the bundle. Use name as default label. String menulabel;/* w w w . java 2 s . c o m*/ try { menulabel = bundle.getString(menuname + ".label"); } catch (MissingResourceException e) { menulabel = menuname; } // Create the menu pane. JMenu menu = new JMenu(menulabel); // For each named item in the menu. for (int i = 0; i < itemnames.length; i++) { // Look up the label for the item, using name as default. String itemlabel; try { itemlabel = bundle.getString(menuname + "." + itemnames[i] + ".label"); } catch (MissingResourceException e) { itemlabel = itemnames[i]; } JMenuItem item = new JMenuItem(itemlabel); // Look up an accelerator for the menu item try { String acceleratorText = bundle.getString(menuname + "." + itemnames[i] + ".accelerator"); item.setAccelerator(KeyStroke.getKeyStroke(acceleratorText)); } catch (MissingResourceException e) { } // Register an action listener and command for the item. if (listener != null) { item.addActionListener(listener); item.setActionCommand(itemnames[i]); } // Add the item to the menu. menu.add(item); } // Return the automatically created localized menu. return menu; }
From source file:Main.java
MyJTree(DefaultMutableTreeNode dmtn) { super(dmtn);//from w w w. j a va2 s . c om mi.addActionListener(this); mi.setActionCommand("insert"); popup.add(mi); mi = new JMenuItem("Remove this node"); mi.addActionListener(this); mi.setActionCommand("remove"); popup.add(mi); addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { popup.show((JComponent) e.getSource(), e.getX(), e.getY()); } } }); }
From source file:components.GlassPaneDemo.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from ww w .j a v a 2 s . c o m*/ */ 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:com.db2eshop.gui.menu.MenuPanel.java
/** {@inheritDoc} */ @Override/*w ww .j a va 2 s .c om*/ public void afterPropertiesSet() throws Exception { this.removeAll(); jMenuFile = new JMenu("File"); fileQuitItem = new JMenuItem("Exit"); fileQuitItem.addActionListener(quitMenuItemListener); jMenuFile.add(fileQuitItem); this.add(jMenuFile); jMenuFinances = new JMenu("Finances"); financesBookingItem = new JMenuItem("Booking"); financesBookingItem.addActionListener(bookingMenuItemListener); jMenuFinances.add(financesBookingItem); this.add(jMenuFinances); this.setVisible(true); }
From source file:DialogTest.java
public DialogFrame() { setTitle("DialogTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // construct a File menu JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w w w . j av a 2 s . co m*/ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); // add About and Exit menu items // The About item shows the About dialog JMenuItem aboutItem = new JMenuItem("About"); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (dialog == null) // first time dialog = new AboutDialog(DialogFrame.this); dialog.setVisible(true); // pop up dialog } }); fileMenu.add(aboutItem); // The Exit item exits the program JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); }