swing无法理解Java1.7PopupFactory源代码
这是java swing 1.7.0中提供的PopupFactory类的私有方法
/**
* Returns the popup type to use for the specified parameters.
*/
private int getPopupType(Component owner, Component contents,
int ownerX, int ownerY) {
int popupType = getPopupType();
if (owner == null || invokerInHeavyWeightPopup(owner)) {
popupType = HEAVY_WEIGHT_POPUP;
}
else if (popupType == LIGHT_WEIGHT_POPUP &&
!(contents instanceof JToolTip) &&
!(contents instanceof JPopupMenu)) {
popupType = MEDIUM_WEIGHT_POPUP;
}
// Check if the parent component is an option pane. If so we need to
// force a heavy weight popup in order to have event dispatching work
// correctly.
Component c = owner;
while (c != null) {
if (c instanceof JComponent) {
if (((JComponent)c).getClientProperty(
PopupFactory_FORCE_HEAVYWEIGHT_POPUP) == Boolean.TRUE) {
popupType = HEAVY_WEIGHT_POPUP;
break;
}
} else if (c instanceof Window) {
Window w = (Window) c;
if (!w.isOpaque() || w.getOpacity() < 1 || w.getShape() != null) {
popupType = HEAVY_WEIGHT_POPUP;
break;
}
}
c = c.getParent();
}
return popupType;
}
我的问题是,在评论中说
// Check if the parent component is an option pane. If so we need to
// force a heavy weight popup in order to have event dispatching work
// correctly.
但当我仔细查看代码片段时,即使是放置在JInternalFrame中的组件(所有者)(放置在JFrame中的DesktopPane中)也会在
popupType=重\u重\u弹出
这与评论不符。请有人解释一下 多谢各位
# 1 楼答案
我在Java8源代码中找到了相应的部分。方法的行为发生了一个小的变化:
所以如果我可以推测一下
PopupFactory_FORCE_HEAVYWEIGHT_POPUP
设置为true李>