JInternalFrame 置于前面并聚焦
如何将 JInternalFrame
推到 JDesktopPane 中所有框架的顶部?
How does one push a JInternalFrame
to the top of all the frames in a JDesktopPane?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试grabFocus()和requestFocus()。其中之一应该有效。我个人只使用了requestFocus()。
try grabFocus() and requestFocus(). One of the should work. I personally used only requestFocus().
阅读 JInternalFrame API 并点击有关“如何使用内部框架”的 Swing 教程的链接,您将在其中找到如何“选择”活动内部框架的工作示例。
Read the JInternalFrame API and follow the link to the Swing tutorial on "How to Use Internal Frames" where you will find a working example of how to "select" the active internal frame.
在此示例中,一个
javax.swing .Action
用于从菜单中选择帧。In this example, a
javax.swing.Action
is used to select frames from a menu.OP 注意到
setSelected
不起作用,他需要手动调用activateFrame
。这听起来与我在GTKLookAndFeel
中遇到的问题类似。我有一个应用程序,它全部连接起来使用setSelected
最终触发activateFrame
。与 Windows 和 Mac 原生外观和感觉配合良好;activateFrame
将被自动调用。在 Ubuntu 上,系统选择的 LaF 是
GTKLookAndFeel
,并且无论出于何种原因,它都没有调用activateFrame
。看起来setSelected
并没有抛出错误或任何东西,它只是没有像其他 LaF 那样调用activateFrame
。我认为这是一个GTKLookAndFeel
兼容性问题。最后我押注了这一点,只是禁止了
GTKLookAndFeel
,而是用Metal
取代了它。Motif
也有兼容的行为(但它太丑了......)。代码看起来像这样:The OP has noted that
setSelected
was not working, and he needed to callactivateFrame
manually. This sounds similar to an issue I was having withGTKLookAndFeel
. I had an application that was all wired up to usesetSelected
to eventually triggeractivateFrame
. Worked fine with Windows and Mac native look and feel;activateFrame
would get called automatically.On Ubuntu, the system selected LaF was
GTKLookAndFeel
and for whatever reason this was not callingactivateFrame
. It didn't appear thatsetSelected
was throwing an error or anything, it just wasn't getting around to callingactivateFrame
as the other LaFs seem to do. I think it's aGTKLookAndFeel
compatibility issue.In the end I punted on this and just prohibited
GTKLookAndFeel
, replacing it withMetal
.Motif
also had the compatible behavior (but it's so ugly...). The code looks something like this:/*通过调用 JInternalFrame 方法 setSelected(false) 取消选择当前的 JInternalFrame
*/然后使用相同的方法选择新的 JInternalFrame;即 setSelected(true)
示例代码:
try{
jframe1.setSelected(假);
jframe2.setSelected(true);
}catch(PropertyVetoException 前){}
/*make current JInternalFrame deselected by calling JInternalFrame method setSelected(false)
*/then select new JInternalFrame using the same method; ie setSelected(true)
sample code:
try{
jframe1.setSelected(false);
jframe2.setSelected(true);
}catch (PropertyVetoException ex) {}
关闭模态 JInternalFrame
参见Zen先生(我)的帖子
Closing a modal JInternalFrame
see the post by Mr. Zen(me)