开发者

How to restrict the focus of JFrame in Swing?

开发者 https://www.devze.com 2023-03-10 16:18 出处:网络
I have a parent JFrame it contain a JButton. functionality of that 开发者_StackOverflow社区button is to open another window.

I have a parent JFrame it contain a JButton. functionality of that 开发者_StackOverflow社区button is to open another window.

I want to restrict the focus of window, means after closing the second window's focus should come into first window(parent). And focus should not come to first window if second window is open.


You should make your second window modal. That said, you'd probably want to make it a JDialog.


yes its possible but workaround for two or more JFrames, but for full funcionalities is needed lots of code,

standard would be one JFrame and another TopLayoutContainers could be JDialog then you can easily play with parent and modalities, toFront , setAlwaysOnTop


As shinoku stated, you can use a modal. However if you have to use a JFrame, you have to implement a WindowListener for the new JFrame. In that implementation for the windowClosing() method you can say originalJFrame.requestFocus(). Of course, your constructor of the WindowListener must be supplied with a reference to the original frame as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号