嗨,这是java swing 1.7.0中提供的PopupFactory类的私有方法。无法理解Java 1.7 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的(这是摆在一个代码片段紧密结合,甚至一个组件(所有者) DesktopPane在JFrame中)在
popupType = HEAVY_WEIGHT_POPUP
它不与comment.Please相符的人解释这 结束 谢谢。
我们没有写评论。你为什么在乎?你想解决什么问题? – camickr
我想解决一个弹出式菜单中的绘画问题,这是不实际的带来我原来的问题我需要提供一个巨大的代码base.so我想了解java swing的行为,以获得一些线索。根据这个源代码,如果应用程序主窗口是JFrame,那么swing将总是产生大量的弹出窗口。但我觉得我错过了一些东西。 – hunter
'把我原来的问题带到这里是不现实的,我需要提供一个庞大的代码库 - - 你需要创建一个[SSCCE](http://sscce.org/)来演示这个问题。 – camickr