當前位置: 首頁>>代碼示例>>Java>>正文


Java JPopupMenu.getPreferredSize方法代碼示例

本文整理匯總了Java中javax.swing.JPopupMenu.getPreferredSize方法的典型用法代碼示例。如果您正苦於以下問題:Java JPopupMenu.getPreferredSize方法的具體用法?Java JPopupMenu.getPreferredSize怎麽用?Java JPopupMenu.getPreferredSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JPopupMenu的用法示例。


在下文中一共展示了JPopupMenu.getPreferredSize方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showPopupMenu

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
/** Shows given popup on given coordinations and takes care about the
 *  situation when menu can exceed screen limits.
 *  Copied from org.netbeans.core.windows.frames.DefaultContainerImpl
 */
private static void showPopupMenu(JPopupMenu popup, Point p, Component comp) {
    SwingUtilities.convertPointToScreen(p, comp);
    Dimension popupSize = popup.getPreferredSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    
    if (p.x + popupSize.width > screenSize.width) {
        p.x = screenSize.width - popupSize.width;
    }
    if (p.y + popupSize.height > screenSize.height) {
        p.y = screenSize.height - popupSize.height;
    }
    SwingUtilities.convertPointFromScreen(p, comp);
    popup.show(comp, p.x, p.y);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:MergeDialogComponent.java

示例2: displayPopup

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
public void displayPopup() {
    JPopupMenu menu = new JPopupMenu();
    populatePopup(menu);
    if (menu.getComponentCount() > 0) {
        Dimension size = menu.getPreferredSize();
        size.width = Math.max(size.width, getWidth());
        menu.setPreferredSize(size);
        menu.show(this, 0, getHeight());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:DropdownButton.java

示例3: showPopupMenu

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
private void showPopupMenu(MouseEvent e) {
    JPopupMenu popup = new JPopupMenu() {
        public void setVisible(boolean visible) {
            if (visible) popupShowing();
            super.setVisible(visible);
            if (!visible) popupHidden();
        }
    };
    
    int row = getSelectedRow();
    Object value = getValueForRow(row);
    Object userValue = getUserValueForRow(row);
    populatePopup(popup, value, userValue);
    
    if (popup.getComponentCount() > 0) {
        if (e == null) {
            boolean b = row == -1;
            int c = b ? -1 : convertColumnIndexToView(mainColumn);
            Rectangle t = b ? getVisibleRect() : getCellRect(row, c, false);
            Dimension s = popup.getPreferredSize();
            int x = t.x + (t.width - s.width) / 2;
            int y = t.y + (b ? (t.height - s.height) / 2 : getRowHeight() - 4);
            popup.show(this, Math.max(x, 0), Math.max(y, 0));
        } else {
            popup.show(this, e.getX(), e.getY());
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:ProfilerTable.java

示例4: displayPopup

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
protected void displayPopup() {
    JPopupMenu menu = new JPopupMenu();
    populatePopup(menu);
    if (menu.getComponentCount() > 0) {
        Dimension size = menu.getPreferredSize();
        size.width = Math.max(size.width, getWidth());
        menu.setPreferredSize(size);
        
        int align = getPopupAlign();
        
        int x;
        switch (align) {
            case SwingConstants.EAST:
            case SwingConstants.NORTH_EAST:
            case SwingConstants.SOUTH_EAST:
                x = getWidth() - size.width;
                break;
            default:
                x = 0;
                break;
        }
        
        int y;
        switch (align) {
            case SwingConstants.NORTH:
            case SwingConstants.NORTH_EAST:
            case SwingConstants.NORTH_WEST:
                y = -size.height;
                break;
            default:
                y = getHeight();
                break;
        }
        
        menu.show(this, x, y);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:PopupButton.java

示例5: getPopupMenuOrigin

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
static Point getPopupMenuOrigin(JPopupMenu popup, Point p) {
    Point newPt = new Point(p);
    Dimension popupSize = popup.getPreferredSize();
    Rectangle screenRect = getScreenRect();
    int popupRight = newPt.x + popupSize.width;
    int popupBottom = newPt.y + popupSize.height;
    int screenRight = screenRect.x + screenRect.width;
    int screenBottom = screenRect.y + screenRect.height;

    if (popupRight > screenRight) { // Are we off the right edge?
        newPt.x = screenRight - popupSize.width;
    }

    if (newPt.x < screenRect.x) { // Are we off the left edge?
        newPt.x = screenRect.x;
    }

    if (popupBottom > screenBottom) { // Are we off the bottom edge?
        newPt.y = screenBottom - popupSize.height;
    }

    if (newPt.y < screenRect.y) { // Are we off the top edge?
        newPt.y = screenRect.y;
    }

    return newPt;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:JPopupMenuUtils.java

示例6: createPopup

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
void createPopup(int xpos, int ypos, boolean contextMenu) {
    if (manager == null) {
        return;
    }

    if (!popupAllowed) {
        return;
    }
    
    if (!isShowing()) {
        return;
    }

    JPopupMenu popup;

    if (contextMenu) {
        popup = Utilities.actionsToPopup(manager.getExploredContext().getActions(true), this);
    } else {
        Action[] actions = NodeOp.findActions(manager.getSelectedNodes());
        popup = Utilities.actionsToPopup(actions, this);
    }

    if ((popup != null) && (popup.getSubElements().length > 0)) {
        Point p = getViewport().getViewPosition();
        p.x = xpos - p.x;
        p.y = ypos - p.y;

        SwingUtilities.convertPointToScreen(p, ListView.this);

        Dimension popupSize = popup.getPreferredSize();
        Rectangle screenBounds = Utilities.getUsableScreenBounds(getGraphicsConfiguration());

        if ((p.x + popupSize.width) > (screenBounds.x + screenBounds.width)) {
            p.x = (screenBounds.x + screenBounds.width) - popupSize.width;
        }

        if ((p.y + popupSize.height) > (screenBounds.y + screenBounds.height)) {
            p.y = (screenBounds.y + screenBounds.height) - popupSize.height;
        }

        SwingUtilities.convertPointFromScreen(p, ListView.this);
        popup.show(this, p.x, p.y);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:45,代碼來源:ListView.java

示例7: dynamicChangeToSubmenu

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:44,代碼來源:JPopupMenuUtils.java


注:本文中的javax.swing.JPopupMenu.getPreferredSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。