Example usage for javax.swing JMenuItem setIcon

List of usage examples for javax.swing JMenuItem setIcon

Introduction

In this page you can find the example usage for javax.swing JMenuItem setIcon.

Prototype

@BeanProperty(visualUpdate = true, description = "The button's default icon")
public void setIcon(Icon defaultIcon) 

Source Link

Document

Sets the button's default icon.

Usage

From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java

/**
 * Initialize the contents of the frame.
 *//*from w w w.j a  va 2 s  .  c om*/
private void initialize() {
    log.info("Plant Evaluator started");
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (reallyExit() == JOptionPane.YES_OPTION) {
                SingleInstance.release();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
    });

    frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    frame.setLocationRelativeTo(null);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$
    mntmExit.setIcon(Icons.IC_LOGOUT_SMALL);
    mntmExit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

        }
    });
    mnFile.add(mntmExit);

    JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$
    menuBar.add(mnEdit);

    JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$
    mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL);
    mntmOptions.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new OptionsDialog(frame);
        }
    });
    mnEdit.add(mntmOptions);

    JMenu mnTools = new JMenu(Messages.getString("AppWindow.mnTools.text")); //$NON-NLS-1$
    menuBar.add(mnTools);

    JMenuItem mntmPostprocessing = new JMenuItem(Messages.getString("AppWindow.mntmPostprocessing.text")); //$NON-NLS-1$
    mntmPostprocessing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
    });
    mnTools.add(mntmPostprocessing);

    JMenuItem mntmPlot = new JMenuItem(Messages.getString("AppWindow.mntmPlot.text")); //$NON-NLS-1$
    mntmPlot.setIcon(Icons.IC_TOOL_PLOT_SMALL);
    mntmPlot.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            DialogUtil.getInstance().showPlotTypeSelection();
        }
    });

    mnTools.add(mntmPlot);

    JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$
    mntmAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                new AboutDialog(frame);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
        }
    });
    mnHelp.add(mntmAbout);

    createContent();

    DialogUtil.getInstance().setMainFrame(frame);

}

From source file:io.github.jeddict.jpa.modeler.widget.attribute.AttributeWidget.java

@Override
protected List<JMenuItem> getPopupMenuItemList() {
    List<JMenuItem> menuList = super.getPopupMenuItemList();

    JMenuItem delete;
    delete = new JMenuItem("Delete");
    delete.setIcon(DELETE_ICON);
    delete.addActionListener(e -> AttributeWidget.this.remove(true));
    menuList.add(0, delete);// w w w .  jav  a2  s. c o  m
    return menuList;
}

From source file:fi.elfcloud.client.tree.DataItemNode.java

private void populatePopupMenu(JPopupMenu menu, BeaverGUI gui) {
    JMenuItem item;
    item = new JMenuItem(Messages.getString("DataItemNode.popup_download")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_SAVE_ITEM));
    item.addActionListener(gui);/*from  w ww.  j ava  2 s .  c  om*/
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/download16.png"))); //$NON-NLS-1$
    menu.add(item);

    item = new JMenuItem(Messages.getString("DataItemNode.popup_modify")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_MODIFY));
    item.addActionListener(gui);
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/modify_rename16.png"))); //$NON-NLS-1$
    menu.add(item);

    item = new JMenuItem(Messages.getString("DataItemNode.popup_move")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_MOVE));
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/move_file16.png"))); //$NON-NLS-1$
    item.addActionListener(gui);
    menu.add(item);

    item = new JMenuItem(Messages.getString("DataItemNode.popup_information")); //$NON-NLS-1$
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/info_file16.png"))); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_INFORMATION));
    item.addActionListener(gui);
    menu.add(item);

    menu.addSeparator();
    item = new JMenuItem(Messages.getString("DataItemNode.popup_delete")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_DELETE));
    item.addActionListener(gui);
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/delete16.png"))); //$NON-NLS-1$
    menu.add(item);
}

From source file:fi.elfcloud.client.tree.ClusterNode.java

private void populatePopupMenu(JPopupMenu menu, BeaverGUI gui) {
    JMenuItem item;
    item = new JMenuItem(Messages.getString("ClusterNode.popup_modify")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_MODIFY));
    item.addActionListener(gui);/*from  ww w  . ja v  a2s .c  o m*/
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/modify_rename16.png"))); //$NON-NLS-1$
    menu.add(item);

    item = new JMenuItem(Messages.getString("ClusterNode.popup_information")); //$NON-NLS-1$
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/info_file16.png"))); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_INFORMATION));
    item.addActionListener(gui);
    menu.add(item);
    menu.addSeparator();

    item = new JMenuItem(Messages.getString("ClusterNode.popup_delete")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_DELETE));
    item.addActionListener(gui);
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/delete16.png"))); //$NON-NLS-1$
    menu.add(item);
}

From source file:es.emergya.ui.gis.HistoryMapViewer.java

@Override
protected JPopupMenu getContextMenu() {
    JPopupMenu menu = new JPopupMenu();
    // Centrar aqui
    JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C);
    cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar"));
    cent.addActionListener(new ActionListener() {

        @Override//from   w w  w.j a v a2s. com
        public void actionPerformed(ActionEvent e) {
            mapView.zoomToFactor(mapView.getEastNorth(eventOriginal.getX(), eventOriginal.getY()),
                    mapView.zoomFactor);
        }
    });
    menu.add(cent);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            eventOriginal = HistoryMapViewer.this.mapView.lastMEvent;
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }
    });
    return menu;
}

From source file:misc.ActionDemo.java

public JMenuBar createMenuBar() {
    JMenuItem menuItem = null;
    JMenuBar menuBar;/*from  w  w  w. ja  v  a2s  . co m*/

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Create the first menu.
    JMenu mainMenu = new JMenu("Menu");

    Action[] actions = { leftAction, middleAction, rightAction };
    for (int i = 0; i < actions.length; i++) {
        menuItem = new JMenuItem(actions[i]);
        menuItem.setIcon(null); //arbitrarily chose not to use icon
        mainMenu.add(menuItem);
    }

    //Set up the menu bar.
    menuBar.add(mainMenu);
    menuBar.add(createAbleMenu());
    return menuBar;
}

From source file:com.projity.menu.ExtMenuFactory.java

/**
 * Initializes a swing menu item/*from   ww w  .j  a  va  2s  . c  o m*/
 * @param item the menu item to initialize
 * @param name the name of the menu item
 * @throws ResourceFormatException if the mnemonic is not a single
 *         character.
 * @throws MissingListenerException if then item action is not found in
 *         the action map.
 */
protected void initializeJMenuItem(JMenuItem item, String name)
        throws ResourceFormatException, MissingListenerException {
    super.initializeJMenuItem(item, name);
    String actionName = getActionStringFromId(name);
    if (actionName != null)
        menuItems.put(actionName, item);
    // Icon
    try {
        String s = getString(name + ICON_SUFFIX);
        ImageIcon icon = IconManager.getIcon(s);
        if (icon != null)
            item.setIcon(icon);
    } catch (MissingResourceException e) {
    }
}

From source file:es.emergya.ui.gis.FleetControlMapViewer.java

@Override
protected JPopupMenu getContextMenu() {
    JPopupMenu menu = new JPopupMenu();

    menu.setBackground(Color.decode("#E8EDF6"));

    // Ttulo//ww w  .j a v  a 2 s  .  c om
    final JMenuItem titulo = new JMenuItem(i18n.getString("map.menu.titulo.puntoGenerico"));
    titulo.setFont(LogicConstants.deriveBoldFont(10.0f));
    titulo.setBackground(Color.decode("#A4A4A4"));
    titulo.setFocusable(false);

    menu.add(titulo);

    menu.addSeparator();

    // Actualizar posicin
    final JMenuItem gps = new JMenuItem(i18n.getString("map.menu.gps"), KeyEvent.VK_P);
    gps.setIcon(LogicConstants.getIcon("menucontextual_icon_actualizargps"));
    menu.add(gps);
    gps.addActionListener(this);
    gps.setEnabled(false);

    menu.addSeparator();

    // Mostrar ms cercanos
    final JMenuItem mmc = new JMenuItem(i18n.getString("map.menu.showNearest"), KeyEvent.VK_M);
    mmc.setIcon(LogicConstants.getIcon("menucontextual_icon_mascercano"));
    mmc.addActionListener(this);
    menu.add(mmc);
    // Centrar aqui
    final JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C);
    cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar"));
    cent.addActionListener(this);
    menu.add(cent);
    // Nueva Incidencia
    final JMenuItem newIncidence = new JMenuItem(i18n.getString("map.menu.newIncidence"), KeyEvent.VK_I);
    newIncidence.setIcon(LogicConstants.getIcon("menucontextual_icon_newIncidence"));
    newIncidence.addActionListener(this);
    menu.add(newIncidence);
    // Calcular ruta desde aqui
    final JMenuItem from = new JMenuItem(i18n.getString("map.menu.route.from"), KeyEvent.VK_D);
    from.setIcon(LogicConstants.getIcon("menucontextual_icon_origenruta"));
    from.addActionListener(this);
    menu.add(from);
    // Calcular ruta hasta aqui
    final JMenuItem to = new JMenuItem(i18n.getString("map.menu.route.to"), KeyEvent.VK_H);
    to.setIcon(LogicConstants.getIcon("menucontextual_icon_destinoruta"));
    to.addActionListener(this);
    menu.add(to);

    menu.addSeparator();

    // Ver ficha [recurso / incidencia]
    final JMenuItem summary = new JMenuItem(i18n.getString("map.menu.summary"), KeyEvent.VK_F);
    summary.setIcon(LogicConstants.getIcon("menucontextual_icon_ficha"));
    summary.addActionListener(this);
    menu.add(summary);
    summary.setEnabled(false);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            eventOriginal = FleetControlMapViewer.this.mapView.lastMEvent;
            gps.setEnabled(false);
            summary.setEnabled(false);
            titulo.setText(i18n.getString("map.menu.titulo.puntoGenerico"));
            menuObjective = null;
            Point p = new Point(mapView.lastMEvent.getX(), mapView.lastMEvent.getY());
            for (Layer l : mapView.getAllLayers()) { // por cada capa...
                if (l instanceof MarkerLayer) { // ...de marcadores
                    for (Marker marker : ((MarkerLayer) l).data) { // miramos
                        // los
                        // marcadores
                        if ((marker instanceof CustomMarker) && marker.containsPoint(p)) { // y si
                            // estamos
                            // pinchando
                            // en uno
                            CustomMarker m = (CustomMarker) marker;
                            log.trace("Hemos pinchado en " + marker);

                            switch (m.getType()) {
                            case RESOURCE:
                                Recurso r = (Recurso) m.getObject();
                                log.trace("Es un recurso: " + r);
                                if (r != null) {
                                    menuObjective = r;
                                    if (r.getPatrullas() != null) {
                                        titulo.setText(
                                                i18n.getString(Locale.ROOT, "map.menu.titulo.recursoPatrulla",
                                                        r.getIdentificador(), r.getPatrullas()));
                                    } else {
                                        titulo.setText(r.getIdentificador());
                                    }
                                    gps.setEnabled(true);
                                    summary.setEnabled(true);
                                }
                                break;
                            case INCIDENCE:
                                Incidencia i = (Incidencia) m.getObject();
                                log.trace("Es una incidencia: " + i);
                                if (i != null) {
                                    menuObjective = i;
                                    titulo.setText(i.getTitulo());
                                    gps.setEnabled(false);
                                    summary.setEnabled(true);
                                }
                                break;
                            case UNKNOWN:
                                log.trace("Hemos pinchado en un marcador desconocido");
                                break;
                            }

                        }
                    }
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

    return menu;
}

From source file:org.jax.maanova.madata.gui.ArrayScatterPlotPanel.java

@SuppressWarnings("serial")
private JMenuBar createMenu() {
    JMenuBar menuBar = new JMenuBar();

    // the file menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.add(this.saveGraphImageAction);
    menuBar.add(fileMenu);//from  w w  w .  jav a2 s . com

    // the tools menu
    JMenu toolsMenu = new JMenu("Tools");
    JMenuItem configureGraphItem = new JMenuItem("Configure Graph...");
    configureGraphItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ArrayScatterPlotPanel.this.chartConfigurationDialog.setVisible(true);
        }
    });
    toolsMenu.add(configureGraphItem);
    toolsMenu.addSeparator();

    toolsMenu.add(new AbstractAction("Zoom Out") {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ArrayScatterPlotPanel.this.autoRangeChart();
        }
    });

    JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point");
    showTooltipCheckbox.setSelected(true);
    this.showTooltip = true;
    showTooltipCheckbox.addItemListener(new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            ArrayScatterPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED;
            ArrayScatterPlotPanel.this.clearProbePopup();
        }
    });
    toolsMenu.add(showTooltipCheckbox);
    menuBar.add(toolsMenu);

    // the help menu
    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Help...");
    Icon helpIcon = new ImageIcon(ArrayScatterPlotPanel.class.getResource("/images/action/help-16x16.png"));
    helpMenuItem.setIcon(helpIcon);
    helpMenuItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            Maanova.getInstance().showHelp("array-scatter-plot", ArrayScatterPlotPanel.this);
        }
    });
    helpMenu.add(helpMenuItem);
    menuBar.add(helpMenu);

    return menuBar;
}

From source file:net.sf.jabref.gui.RightClickMenu.java

/** Sets the font and icon to be used, depending on the group */
private void setGroupFontAndIcon(JMenuItem menuItem, AbstractGroup group) {
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) {
        menuItem.setFont(menuItem.getFont().deriveFont(group.isDynamic() ? Font.ITALIC : Font.PLAIN));
    }/*  w  w w  . java2s.co  m*/
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_ICONS)) {
        switch (group.getHierarchicalContext()) {
        case INCLUDING:
            menuItem.setIcon(IconTheme.JabRefIcon.GROUP_INCLUDING.getSmallIcon());
            break;
        case REFINING:
            menuItem.setIcon(IconTheme.JabRefIcon.GROUP_REFINING.getSmallIcon());
            break;
        default:
            menuItem.setIcon(IconTheme.JabRefIcon.GROUP_REGULAR.getSmallIcon());
            break;
        }
    }
}