List of utility methods to do JPopupMenu
void | attachPopupMenu(final JComponent component, final JPopupMenu popupMenu) Attach popup menu on the given component. component.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger() && e.getComponent() instanceof JTable) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); }); ... |
void | cleanPopupLayoutMetrics(JPopupMenu popupMenu) Cleans the layout metrics of the specified popup menu. if (popupMenu != null) {
popupMenu.putClientProperty(LAYOUT_METRICS, null);
|
Point | computePopupLocation(MouseEvent event, Component rel, JPopupMenu popup) Swing 1.0 and 1.1 have a horrible bug with respect to popup menus. Dimension psz = popup.getSize(); Dimension ssz = Toolkit.getDefaultToolkit().getScreenSize(); Point gLoc = rel.getLocationOnScreen(); Point result = new Point(event.getX(), event.getY()); gLoc.x += event.getX(); gLoc.y += event.getY(); if (psz.width == 0 || psz.height == 0) { int items = popup.getSubElements().length; ... |
JPopupMenu | createPopupMenu() Create a JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new JLabel("Help")); popupMenu.addSeparator(); popupMenu.add(new JLabel("About")); return popupMenu; |
void | createPopupMenu(String menuText, JPopupMenu menu, ActionListener listener) create Popup Menu menu.add(createMenuItem(menuText, listener)); |
void | ensurePopupIsOnScreen(JPopupMenu popup) ensure Popup Is On Screen java.awt.Point location = popup.getLocation(null); java.awt.Dimension size = popup.getSize(null); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); screenSize.height -= 28; javax.swing.SwingUtilities.convertPointToScreen(location, popup); if (location.x < 0) { location.x = 0; } else if (location.x + size.width > screenSize.width) { ... |
Component | findMenuComponent(JPopupMenu menu, String menuComponentName) find Menu Component for (int i = 0; i < menu.getComponentCount(); i++) { Component component = menu.getComponent(i); if (menuComponentName.equals(component.getName())) return component; return null; |
JMenu | findSubMenu(JPopupMenu popupMenu, String name) find Sub Menu int n = popupMenu.getComponentCount(); for (int i = 0; i < n; i++) { Component c = popupMenu.getComponent(i); if (c instanceof JMenu) { JMenu subMenu = (JMenu) c; if (name.equals(subMenu.getName())) { return subMenu; subMenu = findSubMenu(subMenu.getPopupMenu(), name); if (subMenu != null) { return subMenu; return null; |
MouseAdapter | getMousePopupAdapter(final Component component, final JPopupMenu popup) Creates a mouse popup adapter for the given component and popup menu. return new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { handlePopup(e); @Override public void mouseReleased(MouseEvent e) { handlePopup(e); ... |
JPopupMenu | getOnlyPopupMenu(Container owner) get Only Popup Menu return (JPopupMenu) getOnlyComponent(owner, JPopupMenu.class); |