在Swing中是否有一种优雅的方式来确定当前是否在我的框架中显示了任何工具提示?可以摆动告诉我,如果有一个活跃的工具提示?
我正在使用自定义工具提示,所以在我的createToolTip()
方法中设置一个标志将非常容易,但我无法找到找出工具提示何时消失的方法。
ToolTipManager
有一个很好的标志为此,tipShowing,但当然它是private
,他们似乎并没有提供一种方法来实现它。 hideWindow()
不会向工具提示组件(我可以告诉)发出呼叫,所以我没有看到任何方法。
任何人有什么好主意?
更新:我去反思。您可以在此处看到代码:
private boolean isToolTipVisible() {
// Going to do some nasty reflection to get at this private field. Don't try this at home!
ToolTipManager ttManager = ToolTipManager.sharedInstance();
try {
Field f = ttManager.getClass().getDeclaredField("tipShowing");
f.setAccessible(true);
boolean tipShowing = f.getBoolean(ttManager);
return tipShowing;
} catch (Exception e) {
// We'll keep silent about this for now, but obviously we don't want to hit this
// e.printStackTrace();
return false;
}
}