问题
I am in a situation where I create a frame FrameB
from my main frame FrameA
. When the user is working on FrameB
I would like it to be on top of FrameA
even when the user accidentally clicks on FrameA
.
回答1:
Do you have to use a JFrame?
If you use a JDialog instead of a JFrame and assign FrameA as the owner of the dialog through the constructor it will always remain on top of the frame. (Example: How to set the JFrame as a parent to the JDialog)
Otherwise you can use setAlwaysOnTop() from the window class, but this can be dependent on the operating system/window manager.
回答2:
You could consider making FrameB a JDialog instead of JFrame, and set it modal.
来源:https://stackoverflow.com/questions/1620350/keep-jframe-on-top-of-others