JInternalFrame to front and focussed

2019-02-25 18:05发布

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

6条回答
我命由我不由天
2楼-- · 2019-02-25 18:09

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

查看更多
叛逆
3楼-- · 2019-02-25 18:13

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());
查看更多
放我归山
4楼-- · 2019-02-25 18:16

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.

查看更多
一夜七次
5楼-- · 2019-02-25 18:16

/*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) {}

查看更多
Explosion°爆炸
6楼-- · 2019-02-25 18:18

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

查看更多
再贱就再见
7楼-- · 2019-02-25 18:30

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

查看更多
登录 后发表回答