本文整理汇总了Java中javax.swing.JPopupMenu.getLocationOnScreen方法的典型用法代码示例。如果您正苦于以下问题:Java JPopupMenu.getLocationOnScreen方法的具体用法?Java JPopupMenu.getLocationOnScreen怎么用?Java JPopupMenu.getLocationOnScreen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JPopupMenu
的用法示例。
在下文中一共展示了JPopupMenu.getLocationOnScreen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dynamicChange
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
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);
}
}
示例2: runActualTest
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
private static void runActualTest(GraphicsDevice device,
CountDownLatch latch,
JFrame frame,
boolean [] result)
{
Rectangle screenBounds = setLocation(frame, device);
JMenu menu = frame.getJMenuBar().getMenu(0);
menu.doClick();
Point location = menu.getLocationOnScreen();
JPopupMenu pm = menu.getPopupMenu();
Dimension pmSize = pm.getSize();
int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
int height = location.y + yOffset + pmSize.height + menu.getHeight();
int available = screenBounds.y + screenBounds.height - height;
if (available > 0) {
Point origin = pm.getLocationOnScreen();
if (origin.y < location.y) {
// growing upward, wrong!
result[0] = false;
} else {
// growing downward, ok!
result[0] = true;
}
} else {
// there is no space, growing upward would be ok, so we pass
result[0] = true;
}
}
示例3: 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);
}
}