Example usage for javax.swing JPopupMenu doLayout

List of usage examples for javax.swing JPopupMenu doLayout

Introduction

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

Prototype

public void doLayout() 

Source Link

Document

Causes this container to lay out its components.

Usage

From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java

private static void fetchMenuVisualData_JMenu_JPopupMenu(MenuVisualData menuData, Container menuObject)
        throws Exception {
    JPopupMenu popupMenu = menuObject instanceof JPopupMenu ? (JPopupMenu) menuObject
            : ((JMenu) menuObject).getPopupMenu();
    // image/*from   ww  w .j a  v  a  2 s .co m*/
    {
        prepareForPrinting(popupMenu);
        // OSX Java since jdk 1.6.0_20 requires menu invoker to be visible.
        // traverse parents until null or already visible and make sure that all are visible.
        // CHECK: it could flash on Windows.
        Point parentLocation = null;
        Component parent = popupMenu.getInvoker();
        while (parent != null && !parent.isShowing()) {
            Container parent2 = parent.getParent();
            if (parent2 != null) {
                parent = parent2;
            } else {
                break;
            }
        }
        if (parent != null) {
            parentLocation = parent.getLocation();
            prepareForPrinting(parent);
        }
        // fetch image
        try {
            Container popupMenuParent = popupMenu.getParent();
            if (popupMenuParent != null) {
                popupMenuParent.doLayout();
            }
            popupMenu.doLayout();
            menuData.m_menuImage = createComponentShot(popupMenu);
        } finally {
            setVisible(popupMenu, false);
            if (parent != null) {
                parent.setLocation(parentLocation);
                if (parent instanceof JPopupMenu) {
                    setVisible(parent, false);
                }
            }
        }
    }
    // bounds
    {
        org.eclipse.swt.graphics.Rectangle imageBounds = menuData.m_menuImage.getBounds();
        menuData.m_menuBounds = new Rectangle(0, 0, imageBounds.width, imageBounds.height);
    }
    // items
    fetchMenuVisualData_items(menuData, popupMenu);
}