Example usage for javax.swing JPopupMenu show

List of usage examples for javax.swing JPopupMenu show

Introduction

In this page you can find the example usage for javax.swing JPopupMenu show.

Prototype

public void show(Component invoker, int x, int y) 

Source Link

Document

Displays the popup menu at the position x,y in the coordinate space of the component invoker.

Usage

From source file:Main.java

public PopupMenu() {
    super(BoxLayout.Y_AXIS);
    final JPopupMenu menu = new JPopupMenu("Options");
    for (int i = 1; i < 20; i++)
        menu.add(new JMenuItem("Option" + i));

    JLabel clickMe = new JLabel("ClickMe");
    clickMe.setAlignmentX(RIGHT_ALIGNMENT);
    clickMe.addMouseListener(new MouseAdapter() {
        @Override/*from w  ww.  j a v a2 s .c o  m*/
        public void mouseClicked(MouseEvent e) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    add(clickMe);
}

From source file:de.tntinteractive.portalsammler.gui.MainDialog.java

private JButton createConfigButton() {
    final JButton button = new JButton("Konfiguration...");
    button.addActionListener(new ActionListener() {
        @Override// ww  w.  j  av a2  s  .c o  m
        public void actionPerformed(final ActionEvent e) {
            final JPopupMenu menu = MainDialog.this.createConfigMenu();
            final JButton source = (JButton) e.getSource();
            menu.show(source, 0, source.getHeight());
        }
    });
    return button;
}

From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java

private void showPopup(final MouseEvent ev) {
    final JMenuItem open = new JMenuItem("Anzeigen");
    open.addActionListener(new ActionListener() {
        @Override//  w w w  . j  a  va 2 s  . c  o m
        public void actionPerformed(final ActionEvent e) {
            DocumentTable.this.openSelectedRows();
        }
    });

    final JMenuItem export = new JMenuItem("Exportieren");
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            DocumentTable.this.exportSelectedRows();
        }
    });

    final JPopupMenu menu = new JPopupMenu();
    menu.add(open);
    menu.add(export);
    menu.show(ev.getComponent(), ev.getX(), ev.getY());
}

From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java

@Override
protected JButton buildToolBarAddCriterionButton() {
    JButton button = new JButton(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADDCRITERION));
    button.setToolTipText("Add criterion");
    final JPopupMenu addMenu = new JPopupMenu();
    addUtilityAddItemsToMenu(addMenu);//from   w ww . java  2s  . c  om
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            addMenu.show((Component) evt.getSource(), evt.getX(), evt.getY());
        }
    });
    return button;
}

From source file:Main.java

protected void showMenu(int x, int y) {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mi = new JMenuItem("Delete");
    TreePath path = tree.getSelectionPath();
    Object node = path.getLastPathComponent();
    if (node == tree.getModel().getRoot()) {
        mi.setEnabled(false);/*ww  w.  j a va 2  s  . c  om*/
    }
    popup.add(mi);
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            deleteSelectedItems();
        }
    });
    popup.show(tree, x, y);
}

From source file:com.iisigroup.ris.WebFileScanUtilBrowserUI.java

/**
 * Auto-generated method for setting the popup menu for a component
 *//*from  w  ww.j ava2  s  .  c o m*/
private void setComponentPopupMenu(final java.awt.Component parent, final javax.swing.JPopupMenu menu) {
    parent.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mousePressed(java.awt.event.MouseEvent e) {
            if (e.isPopupTrigger())
                menu.show(parent, e.getX(), e.getY());
        }

        public void mouseReleased(java.awt.event.MouseEvent e) {
            if (e.isPopupTrigger())
                menu.show(parent, e.getX(), e.getY());
        }
    });
}

From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java

public VGraphUI() {

    VHintButton zoomIn = new VHintButton(VIcons.ZOOM_IN);
    menu.add(zoomIn);//from  www.  j  a v a 2 s  .  c o  m
    zoomIn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            VGraphCell cell = selectedCell;

            Object o = cell.getUserObject();

            if (o != null && o instanceof VChartPanel) {
                VChartPanel chart = (VChartPanel) o;

                chart.zoomInBoth(0, 0);
                graph.repaint();
            }
        }
    });

    VHintButton zoomOut = new VHintButton(VIcons.ZOOM_OUT);
    menu.add(zoomOut);
    zoomOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            VGraphCell cell = selectedCell;

            Object o = cell.getUserObject();

            if (o != null && o instanceof VChartPanel) {
                VChartPanel chart = (VChartPanel) o;

                chart.zoomOutBoth(0, 0);
                graph.repaint();
            }
        }
    });

    VHintButton settings = new VHintButton(VIcons.APPLICATION_FORM_EDIT);
    menu.add(settings);
    settings.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            VGraphCell cell = selectedCell;

            Object o = cell.getUserObject();

            if (o != null && o instanceof VChartPanel) {
                VChartPanel chart = (VChartPanel) o;

                ChartEditor editor = ChartEditorManager.getChartEditor(chart.getChart());
                int result = JOptionPane.showConfirmDialog(graph.getParent(), editor, "Chart_Properties",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if (result == JOptionPane.OK_OPTION) {
                    editor.updateChart(chart.getChart());
                    graph.repaint();
                }
            }
        }
    });

    VHintButton legend = new VHintButton(VIcons.BRICKS);
    menu.add(legend);
    legend.addActionListener(new ActionListener() {
        /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent e) {

            VGraphCell cell = selectedCell;

            Object o = cell.getUserObject();

            if (o != null && o instanceof VChartPanel) {
                VChartPanel chart = (VChartPanel) o;

                VLegend legend = new VLegend(chart.getChart());

                JPopupMenu menu = new JPopupMenu();
                menu.add(legend);

                menu.show(graph, 0, 0);
            }
        }
    });
}

From source file:de.hshannover.f4.trust.visitmeta.gui.GraphConnection.java

public void showContextMenu(final GraphicWrapper node, Point point) {
    JPopupMenu contextMenu = createContextMenu(node);
    contextMenu.show(mGraphPanel.getPanel(), point.x, point.y);
}

From source file:biz.wolschon.finance.jgnucash.accountProperties.AccountProperties.java

/**
 * @return a panel to edit the settings of this section
 *///from   w ww  . j  a  v a 2 s  .c  o  m
private JPanel getMySettingsPanel() {
    if (mySettingsPanel == null) {
        mySettingsPanel = new JPanel();

        mySettingsPanel.setLayout(new BorderLayout());
        myPropertySheet = new PropertySheetPanel();
        myPropertySheet.setToolBarVisible(true);
        myPropertySheet.setSorting(false);
        myPropertySheet.setMode(PropertySheetPanel.VIEW_AS_CATEGORIES);
        myPropertySheet.setDescriptionVisible(true);

        myPropertySheet.addPropertySheetChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent aEvt) {
                Object property = aEvt.getSource();
                if (property instanceof DefaultProperty) {
                    DefaultProperty prop = (DefaultProperty) property;
                    try {
                        myAccount.setUserDefinedAttribute(prop.getName(), prop.getValue().toString());
                    } catch (Exception e) {
                        LOGGER.error("error in writing userDefinedAttribute", e);
                    }
                }
            }

        });
        myPropertySheet.getTable().addMouseListener(new MouseAdapter() {

            /** show popup if mouseReleased is a popupTrigger on this platform.
             * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
             */
            @Override
            public void mouseReleased(final MouseEvent aE) {
                if (aE.isPopupTrigger()) {
                    JPopupMenu menu = getPropertyPopup();
                    menu.show(myPropertySheet, aE.getX(), aE.getY());
                }
                super.mouseClicked(aE);
            }

            /** show popup if mousePressed is a popupTrigger on this platform.
             * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
             */
            @Override
            public void mousePressed(final MouseEvent aE) {
                if (aE.isPopupTrigger()) {
                    JPopupMenu menu = getPropertyPopup();
                    menu.show(myPropertySheet, aE.getX(), aE.getY());
                }
                super.mouseClicked(aE);
            }

        });
        //
        updateCustomAttributesPanel();
        //        for (ConfigurationSetting setting : getConfigSection().getSettings()) {
        //            MyProperty myProperty = new MyProperty(setting);
        //            myProperty.addPropertyChangeListener(savingPropertyChangeListener);
        //            propertySheet.addProperty(myProperty);
        //        }
        mySettingsPanel.add(new JLabel("custom attributes:"), BorderLayout.NORTH);
        mySettingsPanel.add(myPropertySheet, BorderLayout.CENTER);
        mySettingsPanel.add(getAddCustomAttrPanel(), BorderLayout.SOUTH);

        //        MyPropertyEditorFactory propertyEditorFactory = new MyPropertyEditorFactory();
        //        propertySheet.setEditorFactory(propertyEditorFactory);
        //        propertySheet.setRendererFactory(propertyEditorFactory);

    }
    return mySettingsPanel;
}

From source file:net.sf.xmm.moviemanager.gui.DialogIMDbMultiAdd.java

/**
 * Not yet fully implemented/*from   w  ww  . j  ava 2  s  . c  o  m*/
 * @param e
 */
void handleFileLocationPopup(MouseEvent e) {

    if (!GUIUtil.isRightMouseButton(e))
        return;

    JPopupMenu fileLocationPopup = new JPopupMenu();
    JMenuItem fileLocationItem = new JMenuItem("Open content folder");
    fileLocationPopup.add(fileLocationItem);

    fileLocationPopup.show(fileLocation, e.getX(), e.getY());
}