2009-03-09 2 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이 세 번째가를 갖는 세 JInternalFrame들로 채워집니다 버튼을 누르면 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 

예는 단지 짧은 코드를 유지하기 위해 익명 내부 클래스를 많이 사용하지만 실제 프로그램 아마 그렇게 안 :

예 출력은 다음과 같다.

관련 문제