本文整理汇总了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);
}
示例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());
}
}
示例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());
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}