Example usage for javax.swing JMenuItem setModel

List of usage examples for javax.swing JMenuItem setModel

Introduction

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

Prototype

public void setModel(ButtonModel newModel) 

Source Link

Usage

From source file:org.eclipse.birt.chart.device.swing.SwingEventHandler.java

/**
 * @param muv/*from  w  w  w.  ja  v a 2  s . co m*/
 * @param point
 */
private void openMultiULRs(MultiURLValues muv, Point point) {
    if (popupMenu != null && popupMenu.isValid()) {
        // Remove previous menu object.
        popupMenu.setVisible(false);
        ((JComponent) iun.peerInstance()).remove(popupMenu);
    }

    popupMenu = new JPopupMenu();

    // Create popup menu items.
    for (URLValue uv : muv.getURLValues()) {
        JMenuItem menuItem = new JMenuItem();
        popupMenu.add(menuItem);
        menuItem.setText(uv.getLabel().getCaption().getValue());
        if (uv.getTooltip() != null && uv.getTooltip().length() > 0)
            menuItem.setToolTipText(uv.getTooltip());
        URLMenuItemModel uim = new URLMenuItemModel();
        uim.setURLValue(uv);
        menuItem.setModel(uim);
        menuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                URLValue urlValue = ((URLMenuItemModel) ((JMenuItem) e.getSource()).getModel()).getURLValue();
                openURL(urlValue);
            }
        });

    }

    // Show menu.
    popupMenu.show((JComponent) iun.peerInstance(), point.x, point.y);
}