2009-03-09 11 views

答えて

4

私はこれを試しませんでしたが、クラスの祖先であるContainerクラスはgetComponentZOrderメソッドを含んでいます。 ContainerにあるComponentを渡すと、intのzオーダーが返されます。メソッドによって返された最も小さいz桁の値を持つComponentが最後に描画されます。言い換えれば、上に描画されます。

の配列を返すJDesktopPane.getAllFramesメソッドとの結合で、私は内部フレームのzオーダーを得ることができると思います。

編集

私は実際にそれを試してみたのだが、動作しているようです:上記の例で

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); 

JDesktopPaneは三つ持つ3つのJInternalFrame Sが移入されボタンを押してJInternalFrameとそのzオーダーのリストをSystem.outに出力します。

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 

例は、単にコードを短くするために匿名内部クラスの多くを使用していますが、実際のプログラムは、おそらくそれを行うべきではありません。

出力例は次のとおりです。

関連する問題