Java Code Examples for javax.swing.JPopupMenu#addPopupMenuListener()
The following examples show how to use
javax.swing.JPopupMenu#addPopupMenuListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PopupActionManager.java From ghidra with Apache License 2.0 | 6 votes |
JPopupMenu createPopupMenu(Iterator<DockingActionIf> localActions, ActionContext context) { if (localActions == null) { localActions = IteratorUtils.emptyIterator(); } MenuHandler popupMenuHandler = new PopupMenuHandler(windowManager, context); MenuManager menuMgr = new MenuManager("Popup", '\0', null, true, popupMenuHandler, menuGroupMap); populatePopupMenuActions(localActions, context, menuMgr); if (menuMgr.isEmpty()) { return null; } // Popup menu if items are available JPopupMenu popupMenu = menuMgr.getPopupMenu(); popupMenu.addPopupMenuListener(popupMenuHandler); return popupMenu; }
Example 2
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 6 votes |
private void doSelect(JComponent owner) { invokingComponent = owner; invokingComponent.addMouseListener(this); invokingComponent.addMouseMotionListener(this); pTable.addMouseListener(this); pTable.addMouseMotionListener(this); pTable.getSelectionModel().addListSelectionListener( this ); displayer.getModel().addComplexListDataListener( this ); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); popup = new JPopupMenu(); popup.setBorderPainted( false ); popup.setBorder( BorderFactory.createEmptyBorder() ); popup.add( pTable ); popup.pack(); int locationX = x - (int) pTable.getPreferredSize().getWidth(); int locationY = y + 1; popup.setLocation( locationX, locationY ); popup.setInvoker( invokingComponent ); popup.addPopupMenuListener( this ); popup.setVisible( true ); shown = true; invocationTime = System.currentTimeMillis(); }
Example 3
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 6 votes |
private void doSelect(JComponent owner) { invokingComponent = owner; invokingComponent.addMouseListener(this); invokingComponent.addMouseMotionListener(this); pTable.addMouseListener(this); pTable.addMouseMotionListener(this); pTable.getSelectionModel().addListSelectionListener( this ); controller.getTabModel().addComplexListDataListener( this ); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); popup = new JPopupMenu(); popup.setBorderPainted( false ); popup.setBorder( BorderFactory.createEmptyBorder() ); popup.add( pTable ); popup.pack(); int locationX = x - (int) pTable.getPreferredSize().getWidth(); int locationY = y + 1; popup.setLocation( locationX, locationY ); popup.setInvoker( invokingComponent ); popup.addPopupMenuListener( this ); popup.setVisible( true ); shown = true; invocationTime = System.currentTimeMillis(); }
Example 4
Source File: MenuScroller.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
/** * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the * specified number of items to display in the scrolling region, the * specified scrolling interval, and the specified numbers of items fixed at * the top and bottom of the popup menu. * * @param menu the popup menu * @param scrollCount the number of items to display in the scrolling * portion * @param interval the scroll interval, in milliseconds * @param topFixedCount the number of items to fix at the top. May be 0 * @param bottomFixedCount the number of items to fix at the bottom. May be * 0 * @throws IllegalArgumentException if scrollCount or interval is 0 or * negative or if topFixedCount or bottomFixedCount is negative */ public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) { if (scrollCount <= 0 || interval <= 0) { throw new IllegalArgumentException("scrollCount and interval must be greater than 0"); } if (topFixedCount < 0 || bottomFixedCount < 0) { throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative"); } upItem = new MenuScrollItem(MenuIcon.UP, -1); downItem = new MenuScrollItem(MenuIcon.DOWN, +1); setScrollCount(scrollCount); setInterval(interval); setTopFixedCount(topFixedCount); setBottomFixedCount(bottomFixedCount); this.menu = menu; menu.addPopupMenuListener(menuListener); }
Example 5
Source File: FancyDropDownButton.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public void loggedActionPerformed(ActionEvent ae) { JPopupMenu popup = getPopupMenu(); popup.addPopupMenuListener(popupMenuListener); int popupPrefHeight = (int) popup.getPreferredSize().getHeight(); int buttonY = mainButton.getLocationOnScreen().y; boolean showOnTop = false; GraphicsConfiguration graphicsConf = ApplicationFrame.getApplicationFrame().getGraphicsConfiguration(); if (graphicsConf != null) { int windowHeight = (int) graphicsConf.getBounds().getHeight(); showOnTop = buttonY + mainButton.getHeight() + popupPrefHeight > windowHeight; } if (showOnTop) { popup.show(mainButton, 0, -popupPrefHeight); } else { popup.show(mainButton, 0, mainButton.getHeight()); } }
Example 6
Source File: JDropDownButton.java From jeveassets with GNU General Public License v2.0 | 6 votes |
public JDropDownButton(final String text, final Icon icon, final int popupHorizontalAlignment, final int popupVerticalAlignment) { super(text, icon); if (popupHorizontalAlignment != LEFT && popupHorizontalAlignment != RIGHT && popupHorizontalAlignment != CENTER) { throw new IllegalArgumentException("Must be SwingConstants.RIGHT, SwingConstants.LEFT, or SwingConstants.CENTER"); } if (popupVerticalAlignment != TOP && popupVerticalAlignment != BOTTOM && popupVerticalAlignment != CENTER) { throw new IllegalArgumentException("Must be SwingConstants.TOP, SwingConstants.BOTTOM, or SwingConstants.CENTER"); } ListenerClass listener = new ListenerClass(); this.popupHorizontalAlignment = popupHorizontalAlignment; this.popupVerticalAlignment = popupVerticalAlignment; this.setText(text); this.addMouseListener(listener); this.addKeyListener(listener); jPopupMenu = new JPopupMenu(); jPopupMenu.addPopupMenuListener(listener); menuScroller = new MenuScroller(jPopupMenu); }
Example 7
Source File: MenuScroller.java From megamek with GNU General Public License v2.0 | 6 votes |
/** * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the * specified number of items to display in the scrolling region, the * specified scrolling interval, and the specified numbers of items fixed at * the top and bottom of the popup menu. * * @param menu the popup menu * @param scrollCount the number of items to display in the scrolling portion * @param interval the scroll interval, in milliseconds * @param topFixedCount the number of items to fix at the top. May be 0 * @param bottomFixedCount the number of items to fix at the bottom. May be 0 * @throws IllegalArgumentException if scrollCount or interval is 0 or * negative or if topFixedCount or bottomFixedCount is negative */ public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) { if (scrollCount <= 0 || interval <= 0) { throw new IllegalArgumentException("scrollCount and interval must be greater than 0"); } if (topFixedCount < 0 || bottomFixedCount < 0) { throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative"); } upItem = new MenuScrollItem(MenuIcon.UP, -1); downItem = new MenuScrollItem(MenuIcon.DOWN, +1); setScrollCount(scrollCount); setInterval(interval); setTopFixedCount(topFixedCount); setBottomFixedCount(bottomFixedCount); this.menu = menu; menu.addPopupMenuListener(menuListener); }
Example 8
Source File: ToolsAction.java From netbeans with Apache License 2.0 | 5 votes |
private void fillSubmenu(JPopupMenu pop) { if (lastPopup == null) { pop.addPopupMenuListener(this); lastPopup = pop; removeAll(); Iterator it = generate(toolsAction, false).iterator(); while (it.hasNext()) { java.awt.Component item = (java.awt.Component) it.next(); if (item == null) { addSeparator(); } else { add(item); } } // also work with empty element if (getMenuComponentCount() == 0) { JMenuItem empty = new JMenuItem(NbBundle.getMessage(ToolsAction.class, "CTL_EmptySubMenu")); empty.setEnabled(false); add(empty); } } }
Example 9
Source File: MainProjectActionWithHistory.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Component getToolbarPresenter() { JPopupMenu menu = new JPopupMenu(); JButton button = DropDownButtonFactory.createDropDownButton( new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu); final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText"))); item.setEnabled(isEnabled()); addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String propName = evt.getPropertyName(); if ("enabled".equals(propName)) { item.setEnabled((Boolean) evt.getNewValue()); } else if ("menuText".equals(propName)) { item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue())); } } }); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MainProjectActionWithHistory.this.actionPerformed(e); } }); org.openide.awt.Actions.connect(button, this); menu.addPopupMenuListener(this); return button; }
Example 10
Source File: Canvas.java From Logisim with GNU General Public License v3.0 | 5 votes |
public void showPopupMenu(JPopupMenu menu, int x, int y) { double zoom = getZoomFactor(); if (zoom != 1.0) { x = (int) Math.round(x * zoom); y = (int) Math.round(y * zoom); } myListener.menu_on = true; menu.addPopupMenuListener(myListener); menu.show(this, x, y); }
Example 11
Source File: DropDownButton.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void loggedActionPerformed(ActionEvent ae) { JPopupMenu popup = getPopupMenu(); popup.addPopupMenuListener(popupMenuListener); popup.show(mainButton, isRightAlign() ? -popup.getPreferredSize().width + mainButton.getWidth() + arrowButton.getWidth() : 0, mainButton.getHeight()); }
Example 12
Source File: TrayUI.java From karamel with Apache License 2.0 | 5 votes |
public void setJPopupMenu(JPopupMenu menu) { if (this.menu != null) { this.menu.removePopupMenuListener(popupListener); } this.menu = menu; menu.addPopupMenuListener(popupListener); }
Example 13
Source File: RecentArchivesButton.java From android-classyshark with Apache License 2.0 | 5 votes |
public RecentArchivesButton() { super(); setIcon(GuiMode.getTheme().getRecentIcon()); setToolTipText("History"); popup = new JPopupMenu(); theme.applyTo(popup); popup.setLayout(new BoxLayout(popup, BoxLayout.Y_AXIS)); popup.addPopupMenuListener(new PopupPrintListener()); buildPopup(); setBorderPainted(false); setFocusPainted(true); addMouseListener(new MousePopupListener()); }
Example 14
Source File: AbstractPageListPopupListener.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Construct and show popup menu. * * @param component Component. * @param link Selected page. * @param x Position. * @param y Position. */ private void showPopup(Component component, Page link, int x, int y) { // Menu name JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(link.getTitle()); menuItem.setEnabled(false); popup.add(menuItem); // Create sub menus createPopup(popup, link); popup.show(component, x, y); popup.addPopupMenuListener(this); }
Example 15
Source File: DebugMainProjectAction.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Component getToolbarPresenter() { JPopupMenu menu = new JPopupMenu(); JButton button = DropDownButtonFactory.createDropDownButton( new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu); final JMenuItem item = new JMenuItem(Actions.cutAmpersand((String) delegate.getValue("menuText"))); item.setEnabled(delegate.isEnabled()); delegate.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String propName = evt.getPropertyName(); if ("enabled".equals(propName)) { item.setEnabled((Boolean)evt.getNewValue()); } else if ("menuText".equals(propName)) { item.setText(Actions.cutAmpersand((String) evt.getNewValue())); } else if ("selectedProjects".equals(propName)) { Project[] projects = (Project[]) evt.getNewValue(); if (projects.length == 1) { debugHistorySupport.setSelectedProject(projects[0].getProjectDirectory()); } else { debugHistorySupport.setSelectedProject(null); } } } }); menu.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DebugMainProjectAction.this.actionPerformed(e); } }); try { Action ca = Actions.forID("Debug", "org.netbeans.modules.debugger.ui.actions.ConnectAction"); JMenuItem item2 = new JMenuItem(Actions.cutAmpersand((String) ca.getValue(NAME))); Actions.connect(item2, ca); menu.add(item2); } catch (Exception nsee) { Exceptions.printStackTrace(nsee); } menu.addPopupMenuListener(this); Actions.connect(button, this); return button; }
Example 16
Source File: DropDownButton.java From nextreports-designer with Apache License 2.0 | 4 votes |
public void actionPerformed(ActionEvent event) { JPopupMenu popup = getPopupMenu(); popup.addPopupMenuListener(this); popup.show(mainButton, 0, mainButton.getHeight()); }