List of utility methods to do JPopupMenu
void | refreshPopup(JPopupMenu popup) Mysterious calls to pack(), invalidate() and validate() ;-) popup.pack();
popup.invalidate();
Component c = popup.getParent();
if (c != null) {
c.validate();
|
void | removeConsecutiveSeparators(JPopupMenu popupMenu) Removes all consecutive separators from the given menu. for (int i = 1; i < popupMenu.getComponentCount(); i++) { if (isPopupMenuSeparator(popupMenu.getComponent(i))) { if (isPopupMenuSeparator(popupMenu.getComponent(i - 1))) { popupMenu.remove(i); i--; |
void | removeExtraSeparators(JPopupMenu popup) Removes extra separators, if any. Component[] components = popup.getComponents(); if (components.length <= 1) { return; for (int i = 0; i < components.length; i++) { Component component = components[i]; if (component instanceof JSeparator) { if (i == 0 || i == components.length - 1) { ... |
void | removeTopAndBottomSeparators(JPopupMenu popupMenu) Convenience method that calls the methods removeTopSeparators(JPopupMenu) and removeBottomSeparators(JPopupMenu) with the given pop up menu as parameter. if (popupMenu.getComponentCount() == 0) { return; removeTopSeparators(popupMenu); removeBottomSeparators(popupMenu); |
void | setLocationOnScreen(JPopupMenu visibleMenu, int x, int y) This method exists because popup menus can not be directly moved (the have to be hidden and re-shown). Point invokerLocation = visibleMenu.getInvoker().getLocationOnScreen(); visibleMenu.setVisible(false); visibleMenu.show(visibleMenu.getInvoker(), x - invokerLocation.x, y - invokerLocation.y); |
void | setPopupMenu(final JComponent component, final JPopupMenu popup) Gives a component a popup menu component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { if (e.getButton() > MouseEvent.BUTTON3) return; if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); @Override public void mouseReleased(final MouseEvent e) { if (e.getButton() > MouseEvent.BUTTON3) return; if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); }); |
void | setPopupMenu(final JComponent component, final JPopupMenu popup) Gives a component a popup menu component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); @Override ... |
void | showButtonPopupMenu(AbstractButton button, JPopupMenu popup) show Button Popup Menu if (!popup.isVisible()) {
Dimension size = button.getSize();
popup.show(button, 0, size.height);
|
void | showMenu(JPopupMenu menu, JButton button) Shows specified menu positioned relatively to specified button. Dimension dim = menu.getPreferredSize(); menu.show(button, button.getWidth() - dim.width, button.getHeight()); |
void | showModal(javax.swing.JPopupMenu popupMenu, java.awt.Component invoker, java.awt.Point pt) show Modal java.awt.Component root = javax.swing.SwingUtilities.getRoot(invoker); final javax.swing.JLayeredPane layeredPane; if (root instanceof javax.swing.JFrame) { javax.swing.JFrame window = (javax.swing.JFrame) root; layeredPane = window.getLayeredPane(); } else if (root instanceof javax.swing.JDialog) { javax.swing.JDialog window = (javax.swing.JDialog) root; layeredPane = window.getLayeredPane(); ... |