How would one go about getting the z order (layer depth of ) all the JInternalFrames inside a JDesktopPane. There does not seem to be a straight forward way for this. Any ideas?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Although I haven’t tried this, the
Containerclass (which is an ancestor of theJDesktopPaneclass) contains agetComponentZOrdermethod. By passing aComponentwhich is in theContainer, it will return the z-order of as anint. TheComponentwith the lowest z-order value returned by the method is drawn last, in other words, is drawn on top.Coupling with the
JDesktopPane.getAllFramesmethod, which returns an array ofJInternalFrames, I would think that one could obtain the z-order of the internal frames.Edit
I’ve actually tried it out and it seems to work:
In the above example, a
JDesktopPaneis populated with threeJInternalFrames with the third one having a button which will output a list ofJInternalFrames and its z-order toSystem.out.An example output is the following:
The example uses a lot of anonymous inner classes just to keep the code short, but an actual program probably should not do that.