List of usage examples for javax.swing JMenuItem isEnabled
public boolean isEnabled()
From source file:Main.java
/** Brings the destination menu item into sync with the source item. */ protected static void syncMenuItem(final JMenuItem source, final JMenuItem dest) { final boolean enabled = source.isEnabled(); if (dest.isEnabled() != enabled) dest.setEnabled(enabled);/*w w w.j a va 2 s .c om*/ final int mnemonic = source.getMnemonic(); if (dest.getMnemonic() != mnemonic) dest.setMnemonic(mnemonic); final String text = source.getText(); if (dest.getText() != text) dest.setText(text); final KeyStroke accel = source.getAccelerator(); if (dest.getAccelerator() != accel) dest.setAccelerator(accel); }
From source file:com.projity.menu.MenuManager.java
public boolean isActionEnabled(String id) { Collection buttons = toolBarFactory.getButtonsFromId(id); if (buttons != null) { Iterator i = buttons.iterator(); while (i.hasNext()) { AbstractButton button = (AbstractButton) i.next(); return button.isEnabled(); }//from w w w. java2 s. c o m } else { JMenuItem menuItem = menuFactory.getMenuItemFromId(id); if (menuItem != null) return menuItem.isEnabled(); } return false; }
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.// w ww .j a v a 2 s . c o m */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { authorsPanel = new javax.swing.JPanel(); authorsLabel = new javax.swing.JLabel(); authorsScrollPane = new javax.swing.JScrollPane(); authorsTable = new javax.swing.JTable(); booksPanel = new javax.swing.JPanel(); booksScrollPane = new javax.swing.JScrollPane(); booksTable = new javax.swing.JTable(); booksLabel = new javax.swing.JLabel(); mainMenuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); newAuthorMenuItem = new javax.swing.JMenuItem(); newBookMenuItem = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Book Register 1.0"); setMinimumSize(new java.awt.Dimension(1024, 480)); setPreferredSize(new java.awt.Dimension(1024, 640)); getContentPane().setLayout(new java.awt.GridLayout(2, 1)); authorsPanel.setLayout(new java.awt.BorderLayout()); java.util.ResourceBundle bundle = java.util.ResourceBundle .getBundle("cz/muni/fi/javaseminar/kafa/bookregister/gui/Bundle"); // NOI18N authorsLabel.setText(bundle.getString("Table.authors.title")); // NOI18N authorsPanel.add(authorsLabel, java.awt.BorderLayout.PAGE_START); authorsTable.setModel(authorsTableModel); authorsTable.setMinimumSize(new java.awt.Dimension(480, 640)); authorsScrollPane.setViewportView(authorsTable); authorsPanel.add(authorsScrollPane, java.awt.BorderLayout.CENTER); getContentPane().add(authorsPanel); booksPanel.setLayout(new java.awt.BorderLayout()); booksTable.setModel(booksTableModel); booksScrollPane.setViewportView(booksTable); booksPanel.add(booksScrollPane, java.awt.BorderLayout.CENTER); booksLabel.setText(bundle.getString("Table.books.title")); // NOI18N booksPanel.add(booksLabel, java.awt.BorderLayout.PAGE_START); getContentPane().add(booksPanel); fileMenu.setText(bundle.getString("Menu.file")); // NOI18N newAuthorMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); newAuthorMenuItem.setText(bundle.getString("Menu.file.newAuthor")); // NOI18N newAuthorMenuItem.setMnemonic(KeyEvent.VK_N); newAuthorMenuItem.setAction(spawnNewAuthorWindowAction); newAuthorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK)); fileMenu.add(newAuthorMenuItem); newBookMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK)); newBookMenuItem.setText(bundle.getString("Menu.file.newBook")); // NOI18N newBookMenuItem.setMnemonic(KeyEvent.VK_B); newBookMenuItem.setAction(spawnNewBookWindowAction); newBookMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK)); newBookMenuItem.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JMenuItem m = (JMenuItem) e.getSource(); if (!m.isEnabled()) JOptionPane.showMessageDialog(MainWindow.this, "You have to create an author first."); } }); fileMenu.add(newBookMenuItem); fileMenu.setMnemonic(KeyEvent.VK_F); mainMenuBar.add(fileMenu); setJMenuBar(mainMenuBar); pack(); }
From source file:processing.app.Base.java
private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) { for (int i = 1; i < menu.getItemCount(); i++) { JMenuItem item = menu.getItem(i); if (item != null && item.isEnabled()) { return item; }//from ww w .jav a2 s . co m } throw new IllegalStateException("Menu has no enabled items"); }