List of utility methods to do JMenuItem
void | linkMenuItem(final JMenuItem master, final JMenuItem slave) Forces slave menu item to reflect master menu item using a property change listener. final JMenuItem source = master, dest = slave; source.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent e) { syncMenuItem(source, dest); }); |
void | pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) Esta funcion se usa para pintar la barra de seleccion de los menus. ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); if (menuItem.isOpaque()) { g.setColor(menuItem.getBackground()); g.fillRect(0, 0, menuWidth, menuHeight); if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected()) || model.isArmed()) { RoundRectangle2D.Float boton = new RoundRectangle2D.Float(); boton.x = 1; boton.y = 0; boton.width = menuWidth - 3; boton.height = menuHeight - 1; boton.arcwidth = 8; boton.archeight = 8; GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu()); Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(bgColor); g2D.fill(boton); g.setColor(bgColor.darker()); g2D.draw(boton); g2D.setPaint(grad); g2D.fill(boton); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); g.setColor(oldColor); |
boolean | recursiveUpdateOrInsertMenuItem(MenuElement menu, JMenuItem menuItem, boolean hideOnUpdate) recursive Update Or Insert Menu Item boolean updated = false; for (MenuElement menuEl : menu.getSubElements()) { if (menuEl instanceof JMenuItem) { JMenuItem subMenuItem = (JMenuItem) menuEl; String actionCommand = subMenuItem.getActionCommand(); if (actionCommand.equals(menuItem.getActionCommand())) { if (hideOnUpdate) { subMenuItem.setVisible(false); ... |
boolean | replaceMenuItem(@Nonnull JMenuItem orginalMenuItem, @Nonnull JMenuItem replacementMenuItem) replace a menu item in its parent with another menu item (at the same position in the parent menu) boolean result = false; Container container = orginalMenuItem.getParent(); if (container != null) { int index = container.getComponentZOrder(orginalMenuItem); if (index > -1) { container.remove(orginalMenuItem); container.add(replacementMenuItem, index); result = true; ... |
void | setAccelerator(JMenuItem menuItem, int key, int mask) set Accelerator menuItem.setAccelerator(KeyStroke.getKeyStroke(key, mask)); |
void | setCtrlAccelerator(final JMenuItem jmi, final char accelerator) Sets the accelerator from the given menuitem and the given character with the CTRL. final KeyStroke ks = KeyStroke.getKeyStroke(accelerator, Event.CTRL_MASK);
jmi.setAccelerator(ks);
|
void | setCtrlAccelerator(JMenuItem jmi, char accelerator) Sets the accelerator from the given menuitem and the given character with the CTRL. KeyStroke ks = KeyStroke.getKeyStroke(accelerator, Event.CTRL_MASK); jmi.setAccelerator(ks); |
void | setEnabled(boolean enabled, JMenuItem... items) set Enabled for (JMenuItem item : items)
item.setEnabled(enabled);
|
void | setKeystroke(JMenuItem m, int key) set Keystroke if (key > 0) { if (key != KeyEvent.VK_DELETE) m.setAccelerator(KeyStroke.getKeyStroke(key, Event.CTRL_MASK, false)); else m.setAccelerator(KeyStroke.getKeyStroke(key, 0, false)); |
void | setMnemonic(JMenuItem item, String label, int index) set Mnemonic try { char mnemonic = label.charAt(index); item.setMnemonic(mnemonic); item.setDisplayedMnemonicIndex(index); } catch (IndexOutOfBoundsException e) { |