Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Although I haven't tried this, the <a href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html" rel="nofollow noreferrer"><code>Container</code></a> class (which is an ancestor of the <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JDesktopPane.html" rel="nofollow noreferrer"><code>JDesktopPane</code></a> class) contains a <a href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#getComponentZOrder(java.awt.Component)" rel="nofollow noreferrer"><code>getComponentZOrder</code></a> method. By passing a <a href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html" rel="nofollow noreferrer"><code>Component</code></a> which is in the <code>Container</code>, it will return the z-order of as an <code>int</code>. The <code>Component</code> with the lowest z-order value returned by the method is drawn last, in other words, is drawn on top.</p> <p>Coupling with the <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JDesktopPane.html#getAllFrames()" rel="nofollow noreferrer"><code>JDesktopPane.getAllFrames</code></a> method, which returns an array of <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JInternalFrame.html" rel="nofollow noreferrer"><code>JInternalFrames</code></a>, I would think that one could obtain the z-order of the internal frames.</p> <p><strong>Edit</strong></p> <p>I've actually tried it out and it seems to work:</p> <pre><code>final JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JDesktopPane desktopPane = new JDesktopPane(); desktopPane.add(new JInternalFrame("1") { { setVisible(true); setSize(100, 100); } }); desktopPane.add(new JInternalFrame("2") { { setVisible(true); setSize(100, 100); } }); desktopPane.add(new JInternalFrame("3") { JButton b = new JButton("Get z-order"); { setVisible(true); setSize(100, 100); getContentPane().add(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JInternalFrame[] iframes = desktopPane.getAllFrames(); for (JInternalFrame iframe : iframes) { System.out.println(iframe + "\t" + desktopPane.getComponentZOrder(iframe)); } } }); } }); f.setContentPane(desktopPane); f.setLocation(100, 100); f.setSize(400, 400); f.validate(); f.setVisible(true); </code></pre> <p>In the above example, a <code>JDesktopPane</code> is populated with three <code>JInternalFrame</code>s with the third one having a button which will output a list of <code>JInternalFrame</code>s and its z-order to <code>System.out</code>.</p> <p>An example output is the following:</p> <pre><code>JDesktopPaneTest$3[... tons of info on the frame ...] 0 JDesktopPaneTest$2[... tons of info on the frame ...] 1 JDesktopPaneTest$1[... tons of info on the frame ...] 2 </code></pre> <p>The example uses a lot of anonymous inner classes just to keep the code short, but an actual program probably should not do that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload