JInternalFrame 置于前面并聚焦

发布于 2024-10-05 20:59:22 字数 64 浏览 2 评论 0原文

如何将 JInternalFrame 推到 JDesktopPane 中所有框架的顶部?

How does one push a JInternalFrame to the top of all the frames in a JDesktopPane?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

节枝 2024-10-12 20:59:22

尝试grabFocus()和requestFocus()。其中之一应该有效。我个人只使用了requestFocus()。

try grabFocus() and requestFocus(). One of the should work. I personally used only requestFocus().

甜警司 2024-10-12 20:59:22

阅读 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.

森林迷了鹿 2024-10-12 20:59:22

在此示例中,一个 javax.swing .Action 用于从菜单中选择帧。

In this example, a javax.swing.Action is used to select frames from a menu.

摘星┃星的人 2024-10-12 20:59:22

OP 注意到 setSelected 不起作用,他需要手动调用 activateFrame。这听起来与我在 GTKLookAndFeel 中遇到的问题类似。我有一个应用程序,它全部连接起来使用 setSelected 最终触发 activateFrame。与 Windows 和 Mac 原生外观和感觉配合良好; activateFrame 将被自动调用。

在 Ubuntu 上,系统选择的 LaF 是 GTKLookAndFeel,并且无论出于何种原因,它都没有调用 activateFrame。看起来 setSelected 并没有抛出错误或任何东西,它只是没有像其他 LaF 那样调用 activateFrame 。我认为这是一个 GTKLookAndFeel 兼容性问题。

最后我押注了这一点,只是禁止了 GTKLookAndFeel,而是用 Metal 取代了它。 Motif 也有兼容的行为(但它太丑了......)。代码看起来像这样:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
if (UIManager.getLookAndFeel() instanceof com.sun.java.swing.plaf.gtk.GTKLookAndFeel)
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

The OP has noted that setSelected was not working, and he needed to call activateFrame manually. This sounds similar to an issue I was having with GTKLookAndFeel. I had an application that was all wired up to use setSelected to eventually trigger activateFrame. 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 calling activateFrame. It didn't appear that setSelected was throwing an error or anything, it just wasn't getting around to calling activateFrame as the other LaFs seem to do. I think it's a GTKLookAndFeel compatibility issue.

In the end I punted on this and just prohibited GTKLookAndFeel, replacing it with Metal. Motif also had the compatible behavior (but it's so ugly...). The code looks something like this:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
if (UIManager.getLookAndFeel() instanceof com.sun.java.swing.plaf.gtk.GTKLookAndFeel)
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
海螺姑娘 2024-10-12 20:59:22

/*通过调用 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) {}

瑕疵 2024-10-12 20:59:22

关闭模态 JInternalFrame
参见Zen先生(我)的帖子

Closing a modal JInternalFrame
see the post by Mr. Zen(me)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文