How to determine if one rotation window is above another

I have several unrelated JFrames open in my application. And at the exit of the application, I must remember the preferences of all of them in order to restore them to the same appearance as before the exit.

The problem is that these frames are located one above the other, they must be restored in the same order. Another way: smaller frames will not be displayed under larger ones.

QUESTION: How can I determine the deep location in each of the frames in this case?

UPD: I detect this case by comparing frames' location/size pairs , but I still cannot solve the problem.

UPD2: Note. several jframes ui not standard. One JFrame displayed by default, but the user can use several if he wants . My question is not about how to make single JFrame , but how to operate with several ones .

+4
source share
3 answers

Just use Window.isFocusableWindow () to verify that the JFrame is on top of everything else.

Although I will also insist on not using more than one JFrame for any application JFrame

+3
source

QUESTION: How can I determine the deep location of each of the frames in this case?

UPD: I detect this case by comparing location / frame size pairs, but I still don't understand how to solve my problem.

  • you can loop inside arrays of top-level containers

.

  Window[] wins = Window.getWindows(); for (int i = 0; i < wins.length; i++) { if (wins[i] instanceof JFrame) { wins[i].wheteverMethodImplementedInConcreteAPI; } //else if ... JDialog, JWindow, ei AWT Containers } 

.

Hmm .. I can’t find the answer to my question "to your link actually ... Except for bad practice for using multiple JFrames :)

.

  • see Remove top-level container at runtime , then there is

    • use CardLayout instead of a bunch of JFrames , no popups

    • use CardLayout instead of the CardLayout bundle and for another popup to use JDialog () / JWindow ( JTextComponents not editable)

    • use CardLayout instead of the CardLayout bundle, and for another pop-up window to use JDialog () / JWindow ( JTextComponents not editable) using CardLayout for multiple switching switches view in the pop-up container, using the Xxx.pack() note is required for proper calibration after switching the card.

    • set the JFrame as the parent for JDialog() / JWindow() , then the parent vs child - the question is isVisible , isDisplayable , etc. and leisure events implemented in WindowEvent

+2
source

You can use getComponentZOrder () to get the z-index of frames and set it using setComponentZOrder () .

0
source

Source: https://habr.com/ru/post/1493645/


All Articles