Java Code Examples for javax.swing.JPopupMenu#isShowing()

The following examples show how to use javax.swing.JPopupMenu#isShowing() . 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: JPopupMenuUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void dynamicChange(final JPopupMenu popup, boolean usedToBeContained) {
        if (!popup.isShowing()) {
            return;
        }

        if (isProblemConfig()) {
            callRefreshLater(popup);

            return;
        }

        refreshPopup(popup);

        Point p = popup.getLocationOnScreen();
        Point newPt = getPopupMenuOrigin(popup, p);

        boolean willBeContained = willPopupBeContained(popup, newPt);

        if (usedToBeContained != willBeContained) {
            popup.setVisible(false);
        }

        if (!newPt.equals(p)) {
//            if (!NO_POPUP_PLACEMENT_HACK) {
//                popup.setLocation(newPt.x, newPt.y);
//            }
        }

        if (usedToBeContained != willBeContained) {
            popup.setVisible(true);
        }
    }
 
Example 2
Source File: JPopupMenuUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isPopupContained(JPopupMenu popup) {
    if (!popup.isShowing()) {
        return false;
    }

    return willPopupBeContained(popup, popup.getLocationOnScreen());
}
 
Example 3
Source File: JPopupMenuUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean willPopupBeContained(JPopupMenu popup, Point origin) {
    if (!popup.isShowing()) {
        return false;
    }

    Window w = SwingUtilities.windowForComponent(popup.getInvoker());
    Rectangle r = new Rectangle(origin, popup.getSize());

    return (w != null) && w.getBounds().contains(r);
}
 
Example 4
Source File: JPopupMenuUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void dynamicChangeToSubmenu(JPopupMenu popup, boolean usedToBeContained) {
    Object invoker = popup.getInvoker();

    if (!(invoker instanceof JMenu)) {
        return;
    }

    JMenu menu = (JMenu) invoker;

    if (!popup.isShowing()) {
        return;
    }

    if (isProblemConfig()) {
        callRefreshLater2(popup, menu);

        return;
    }

    refreshPopup(popup);

    Point p = popup.getLocationOnScreen();
    Dimension popupSize = popup.getPreferredSize();
    Rectangle popupRect = new Rectangle(p, popupSize);
    Rectangle screenRect = getScreenRect();
    boolean willBeContained = isPopupContained(popup);

    if (!screenRect.contains(popupRect)) {
        /*
         * The menu grew off the edge of the screen.
         */
        menu.setPopupMenuVisible(false);
        menu.setPopupMenuVisible(true);
    } else if (usedToBeContained != willBeContained) {
        /*
         * The menu grew off the edge of the containing window.
         * Use the setVisible() hack to change the menu from
         * lightweight to heavyweight.
         */
        popup.setVisible(false);
        popup.setVisible(true);
    }
}