Example usage for javax.swing JPopupMenu JPopupMenu

List of usage examples for javax.swing JPopupMenu JPopupMenu

Introduction

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

Prototype

public JPopupMenu() 

Source Link

Document

Constructs a JPopupMenu without an "invoker".

Usage

From source file:jmupen.MyListSelectionListener.java

@Override
public void mousePressed(MouseEvent e) {
    list.setSelectedIndex(list.locationToIndex(e.getPoint()));
    int index = list.getSelectedIndex();
    if (SwingUtilities.isRightMouseButton(e)) {
        JPopupMenu menu = new JPopupMenu();
        JMenuItem item = new JMenuItem("Remove");
        item.addActionListener(new ActionListener() {
            @Override/*w  w w .  java  2  s  .  com*/
            public void actionPerformed(ActionEvent e) {
                if (index != -1) {
                    try {
                        System.out.println("Linea: " + index + " " + model.get(index));
                        model.removeElementAt(index);
                        removeLines(index, JMupenUtils.getRecents().toFile());
                        JMupenUtils.setGames(JMupenUtils.getGamesFromFile(JMupenUtils.getRecents()));
                    } catch (IOException ex) {
                        System.err.println("Error removing recent game. " + ex.getLocalizedMessage());
                    }
                }
            }
        });
        menu.add(item);
        menu.show(list, e.getX(), e.getY());
    }
}

From source file:hermes.browser.components.ClasspathGroupTable.java

private void init() {
    final JPopupMenu popupMenu = new JPopupMenu();
    final JMenuItem addItem = new JMenuItem("Add Group");
    final JMenuItem removeItem = new JMenuItem("Remove Group");
    final JMenuItem renameItem = new JMenuItem("Rename");

    popupMenu.add(addItem);//from  w  w w  . jav  a  2s.c o m
    popupMenu.add(removeItem);
    popupMenu.add(renameItem);

    addItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                doAddGroup();
                dialog.setDirty();
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }
        }
    });

    removeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (getSelectedRowCount() > 0) {
                for (int row : getSelectedRows()) {
                    getClasspathGroupTableModel().removeRow(row);
                }
                dialog.setDirty();
            }
        }
    });

    renameItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (getSelectedRow() != -1) {
                doRename();
            }
        }
    });

    mouseAdapter = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                removeItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0);
                renameItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0);
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };

    addMouseListener(mouseAdapter);
    getTableHeader().addMouseListener(mouseAdapter);

    if (dialog != null) {
        addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                //
                // Think this is ok, seems 2 do the job.

                if (evt.getPropertyName().equals("tableCellEditor")) {
                    dialog.setDirty();
                }
            }
        });
    }
}

From source file:it.unibas.spicygui.vista.QueryTabbedPane.java

public void creaPopUp() {
    this.popUpMenu = new JPopupMenu();
    this.popUpMenu.add(new ActionIncreaseFont(textArea));
    this.popUpMenu.add(new ActionDecreaseFont(textArea));
    this.popUpMenu.add(new ActionExportQuery(textArea));
    if (xQuery) {
        MappingTask mappingTask = scenario.getMappingTask();
        if (mappingTask.getSourceProxy().getType().equalsIgnoreCase(SpicyEngineConstants.TYPE_XML)) {
            JMenu jMenu = new JMenu(NbBundle.getMessage(Costanti.class, Costanti.ACTION_EXECUTE_XQUERY));
            this.popUpMenu.add(jMenu);
            List<String> sourceInstancesName = (List<String>) mappingTask.getSourceProxy()
                    .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
            for (String instance : sourceInstancesName) {
                jMenu.add(new ActionExecuteXQuery(instance, scenario.getMappingTask()));
            }//w w  w  . j  a  va2  s.co m
        }
    } else {
        this.popUpMenu.add(new ActionExecuteSql(textArea, scenario.getMappingTask()));
    }
    this.textArea.addMouseListener(new PopUpListener());
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPopupButton.java

public DesktopPopupButton() {
    popup = new JPopupMenu();

    impl = new JButton();
    impl.setLayout(new BoxLayout(impl, BoxLayout.X_AXIS));

    captionLabel = new JLabel();
    impl.add(Box.createHorizontalGlue());
    impl.add(captionLabel);/*w ww .  jav a2s . c  o m*/
    captionLabel.setAlignmentX(CENTER_ALIGNMENT);

    rightIcon = new JLabel();
    rightIcon.setIcon(resources.getIcon(DROP_DOWN_ICON));
    rightIcon.setAlignmentX(CENTER_ALIGNMENT);
    impl.add(rightIcon);
    impl.add(Box.createHorizontalGlue());

    impl.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (popup.isVisible())
                popup.setVisible(false);
            else
                showPopup();
        }
    });
    DesktopComponentsHelper.adjustSize(impl);
}

From source file:de.tbuchloh.kiskis.gui.widgets.BasicTextField.java

private void init() {
    _copyAction = M.createAction(this, "onCopyToClipboard");
    _specialActionsMenu = new JPopupMenu();
    for (final Object element : getContextMenuActions()) {
        final Action act = (Action) element;
        _specialActionsMenu.add(act);/*from  w w  w .ja  va 2 s.  co  m*/
    }

    addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                return;
            }
            final int x = 0; // _pwdField.getWidth()
            // - _specialActionsMenu.getWidth();
            final int y = getHeight();

            LOG.debug("Show context menu x=" + x + ", y=" + y);
            _specialActionsMenu.show(BasicTextField.this, x, y);
        }
    });
}

From source file:net.sf.jhylafax.AbstractQueuePanel.java

public AbstractQueuePanel(String queueName) {
    this.queueName = queueName;

    setLayout(new BorderLayout());
    setBorder(GUIHelper.createEmptyBorder(10));

    resetQueueTableAction = new ResetQueueTableAction();

    tablePopupMenu = new JPopupMenu();

    TableSorter sorter = new TableSorter(getTableModel());
    queueTable = new ColoredTable(sorter);
    queueTableLayout = new TableLayout(queueTable);
    initializeTableLayout();//  w w w  . j  a v  a2s. co  m
    queueTableLayout.getHeaderPopupMenu().add(new JMenuItem(resetQueueTableAction));
    add(new JScrollPane(queueTable), BorderLayout.CENTER);

    queueTable.setShowVerticalLines(true);
    queueTable.setShowHorizontalLines(false);
    queueTable.setAutoCreateColumnsFromModel(true);
    queueTable.setIntercellSpacing(new java.awt.Dimension(2, 1));
    queueTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queueTable.getSelectionModel().addListSelectionListener(this);
    queueTable.addMouseListener(new PopupListener(tablePopupMenu));

    queueTable.setDefaultRenderer(Long.class, new FilesizeCellRenderer());
    queueTable.setDefaultRenderer(String.class, new StringCellRenderer());
    queueTable.setDefaultRenderer(Date.class, new TimeCellRenderer());
    queueTable.setDefaultRenderer(FaxJob.State.class, new StateCellRenderer());

    buttonPanel = new JPanel(new FlowLayout());
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:FileTree3.java

public FileTree3() {
    super("Directories Tree [Tool Tips]");
    setSize(400, 300);// w  ww.j ava 2 s  .c  om

    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"));

    DefaultMutableTreeNode node;
    File[] roots = File.listRoots();
    for (int k = 0; k < roots.length; k++) {
        node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
        top.add(node);
        node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    m_model = new DefaultTreeModel(top);
    // NEW
    m_tree = new JTree(m_model) {
        public String getToolTipText(MouseEvent ev) {
            if (ev == null)
                return null;
            TreePath path = m_tree.getPathForLocation(ev.getX(), ev.getY());
            if (path != null) {
                FileNode fnode = getFileNode(getTreeNode(path));
                if (fnode == null)
                    return null;
                File f = fnode.getFile();
                return (f == null ? null : f.getPath());
            }
            return null;
        }
    };
    ToolTipManager.sharedInstance().registerComponent(m_tree);

    m_tree.putClientProperty("JTree.lineStyle", "Angled");

    TreeCellRenderer renderer = new IconCellRenderer();
    m_tree.setCellRenderer(renderer);

    m_tree.addTreeExpansionListener(new DirExpansionListener());

    m_tree.addTreeSelectionListener(new DirSelectionListener());

    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);

    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);

    m_display = new JTextField();
    m_display.setEditable(false);
    getContentPane().add(m_display, BorderLayout.NORTH);

    m_popup = new JPopupMenu();
    m_action = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (m_clickedPath == null)
                return;
            if (m_tree.isExpanded(m_clickedPath))
                m_tree.collapsePath(m_clickedPath);
            else
                m_tree.expandPath(m_clickedPath);
        }
    };
    m_popup.add(m_action);
    m_popup.addSeparator();

    Action a1 = new AbstractAction("Delete") {
        public void actionPerformed(ActionEvent e) {
            m_tree.repaint();
            JOptionPane.showMessageDialog(FileTree3.this, "Delete option is not implemented", "Info",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    };
    m_popup.add(a1);

    Action a2 = new AbstractAction("Rename") {
        public void actionPerformed(ActionEvent e) {
            m_tree.repaint();
            JOptionPane.showMessageDialog(FileTree3.this, "Rename option is not implemented", "Info",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    };
    m_popup.add(a2);
    m_tree.add(m_popup);
    m_tree.addMouseListener(new PopupTrigger());

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}

From source file:com.eviware.soapui.support.log.JLogList.java

public JLogList(String title) {
    super(new BorderLayout());
    this.title = title;

    model = new LogListModel();
    logList = new JList(model);
    logList.setToolTipText(title);//from   ww  w  .j  a va  2  s  .c  om
    logList.setCellRenderer(new LogAreaCellRenderer());
    logList.setPrototypeCellValue("Testing 123");
    logList.setFixedCellWidth(-1);

    JPopupMenu listPopup = new JPopupMenu();
    listPopup.add(new ClearAction());
    enableAction = new EnableAction();
    enableMenuItem = new JCheckBoxMenuItem(enableAction);
    enableMenuItem.setSelected(true);
    listPopup.add(enableMenuItem);
    listPopup.addSeparator();
    listPopup.add(new CopyAction());
    listPopup.add(new SetMaxRowsAction());
    listPopup.addSeparator();
    listPopup.add(new ExportToFileAction());

    logList.setComponentPopupMenu(listPopup);

    setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JScrollPane scrollPane = new JScrollPane(logList);
    UISupport.addPreviewCorner(scrollPane, true);
    add(scrollPane, BorderLayout.CENTER);

    requestAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(requestAttributes, Color.BLUE);

    responseAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(responseAttributes, Color.GREEN);

    try {
        maxRows = Long.parseLong(SoapUI.getSettings().getString("JLogList#" + title, "1000"));
    } catch (NumberFormatException e) {
    }
}

From source file:com.intuit.tank.tools.debugger.RequestResponsePanel.java

public void init() {
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
    pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    requestTA = new RTextArea();
    requestTA.setEditable(false);//from  w  ww  .  ja  v  a 2  s.c  o m
    requestTA.setAutoscrolls(true);
    requestTA.setHighlightCurrentLine(false);
    JScrollPane sp1 = new JScrollPane(requestTA, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    JPanel reqPane = new JPanel(new BorderLayout());
    // JPanel titlePanel = new JPanel(new BorderLayout());
    // titlePanel.add(BorderLayout.WEST, new JLabel("Request:"));
    // JButton saveBT = new JButton(parent.getDebuggerActions().getSaveReqResponseAction());
    // saveBT.setText("");
    // titlePanel.add(BorderLayout.EAST, saveBT);
    reqPane.add(BorderLayout.NORTH, new JLabel("Request:"));
    reqPane.add(BorderLayout.CENTER, sp1);
    pane.setTopComponent(reqPane);

    responseTA = new RTextArea();
    responseTA.setEditable(false);
    responseTA.setAutoscrolls(true);
    responseTA.setHighlightCurrentLine(false);
    JScrollPane sp2 = new JScrollPane(responseTA, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    JPanel responsePane = new JPanel(new BorderLayout());
    responsePane.add(BorderLayout.NORTH, new JLabel("Response:"));
    responsePane.add(BorderLayout.CENTER, sp2);
    pane.setBottomComponent(responsePane);
    pane.setDividerLocation(0.5D);
    pane.setResizeWeight(0.5D);

    add(pane, BorderLayout.CENTER);
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(parent.getDebuggerActions().getSaveReqResponseAction());
    requestTA.setPopupMenu(popupMenu);
    responseTA.setPopupMenu(popupMenu);
}

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

private void initGUI() {
    final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
    try {/*from www. j a v  a 2 s.c o  m*/
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("browser source code");
        {
            informationMenu = new JPopupMenu();
            setComponentPopupMenu(this, informationMenu);
        }
        {
            ListModel openFileListModel = new DefaultListModel();
            openFileList = new JList();
            openFileList.setModel(openFileListModel);
            getContentPane().add(openFileList, BorderLayout.NORTH);
            openFileList.setPreferredSize(new java.awt.Dimension(663, 281));
            openFileList.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent evt) {
                    swingUtil.invokeAction("openFileList.valueChanged", evt);
                }
            });
            openFileList.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseMoved(MouseEvent evt) {
                    swingUtil.invokeAction("openFileList.mouseMoved", evt);
                }
            });
            openFileList.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent evt) {
                    swingUtil.invokeAction("openFileList.keyPressed", evt);
                }
            });
        }
        {
            jPanel1 = new JPanel();
            GroupLayout jPanel1Layout = new GroupLayout((JComponent) jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.SOUTH);
            jPanel1.setPreferredSize(new java.awt.Dimension(478, 35));
            {
                openSelected = new JButton();
                openSelected.setText("open all");
                openSelected.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("openSelected.actionPerformed", evt);
                    }
                });
            }
            jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup().addContainerGap(178, 178)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(174, Short.MAX_VALUE));
            jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup().addGap(7)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 6, Short.MAX_VALUE));
        }
        {
            informationMenu = new JPopupMenu();
        }

        this.setSize(486, 350);
        this.setLocationRelativeTo(null);

        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        int initialDelay = ToolTipManager.sharedInstance().getInitialDelay();
        ToolTipManager.sharedInstance().setInitialDelay(0);
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        swingUtil.addAction("openFileList.mouseClicked", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                int pos = openFileList.getLeadSelectionIndex();
                if (pos == -1) {
                    return;
                }
                setOpenFileListToolTip();
                MouseEvent eeev = (MouseEvent) evt;
                if (eeev.getClickCount() != 2) {
                    return;
                }
                MFile file = (MFile) model.elementAt(pos);
                openSource(file.file);
            }
        });
        final JListUtil jlistUtil = JListUtil.newInstance(openFileList);
        swingUtil.addAction("openFileList.keyPressed", new Action() {
            public void action(EventObject evt) throws Exception {
                jlistUtil.defaultJListKeyPressed((KeyEvent) evt);
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openSelected.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                    MFile file = (MFile) enu.nextElement();
                    openSource(file.file);
                }
            }
        });
        swingUtil.addAction("openFileList.mouseMoved", new Action() {
            public void action(EventObject evt) throws Exception {
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openFileList.valueChanged", new Action() {
            public void action(EventObject evt) throws Exception {
                System.out.println(evt);
                setOpenFileListToolTip();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}