Search code examples
javaswingwindowlistener

How to restrict the focus of JFrame in Swing?


I have a parent JFrame it contain a JButton. functionality of that 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.


Solution

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