2013-02-17 12 views
0

안녕하세요, 기본/최소 및 최대 button.It 기본 상태로 있지만 기본 프레임을 복원 할 때 제대로 작동하지 않는 내부 프레임이 몇 개 있습니다. 두 내부 프레임이 있습니다. 최대 state.Now에 분 상태와 하나의 당신은 최대 주요 컨테이너는 모든 분 내부 프레임> 첨부 된 스크린 샷Jinternalframe이 제대로 작동하지 않습니다.

package tryout; 
import java.awt.Component; 
import java.awt.EventQueue; 
import java.awt.event.*; 
import java.util.ArrayList; 
import java.util.List; 

import javax.swing.*; 

public class Test3 { 

    public static void main(String[] args) { 
     new Test3(); 
    } 

    private int xpos = 0; 
    private int ypos = 0; 

    public Test3() { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
       } catch (Exception exp) { 
        exp.printStackTrace(); 
       } 
       DesktopPane pane = new DesktopPane(); 
       pane.add(newInternalFrame()); 
       pane.add(newInternalFrame()); 
       pane.add(newInternalFrame()); 

       JFrame frame = new JFrame(); 
       frame.add(pane); 
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
       frame.setSize(400, 400); 
       frame.setLocationRelativeTo(null); 
       frame.setVisible(true); 

      } 
     }); 
    } 

    public JInternalFrame newInternalFrame() { 
     JInternalFrame inf = new JInternalFrame("Blah", true, false, true, true); 
     inf.setLocation(xpos, ypos); 
     inf.setSize(100, 100); 
     inf.setVisible(true); 
inf.repaint(); 
inf.revalidate(); 
     xpos += 50; 
     ypos += 50; 

     return inf; 
    } 

    public class DesktopPane extends JDesktopPane { 

     @Override 
     public void doLayout() { 
      super.doLayout(); 
      List<Component> icons = new ArrayList<Component>(25); 
      int maxLayer = 0; 

      for (Component comp : getComponents()) { 
       if (comp instanceof JInternalFrame.JDesktopIcon) { 
        icons.add(comp); 
        maxLayer = Math.max(getLayer(comp), maxLayer); 
       } 
      } 

      maxLayer++; 
      int x = 0; 
      for (Component icon : icons) { 

       int y = getHeight() - icon.getHeight(); 
       icon.setLocation(x, y); 
       x += icon.getWidth(); 
       setLayer(icon, maxLayer); 

      } 
     } 
    /* public void doLayout() { 
      super.doLayout(); 
      List<Component> icons = new ArrayList<Component>(25); 
      for (Component comp : getComponents()) { 
       if (comp instanceof JInternalFrame.JDesktopIcon) { 
        icons.add(comp); 
       } 
      } 

      int x = 0; 
      for (Component icon : icons) { 

       int y = getHeight() - icon.getHeight(); 
       icon.setLocation(x, y); 
       x += icon.getWidth(); 

      } 
     }*/ 
    } 
} 
+1

시도한 Mac 및 Windows 7에서 문제를 재현 할 수 없습니다. – MadProgrammer

+0

설명하는 문제가 발생합니다. 문제는 doLayout() 코드를 재정의하려고하는 이유입니다. 기본 레이아웃 코드를 복제하려고 시도하는 것 같습니다. doLayout() 메서드를 제거하십시오. – camickr

+0

@camickr 답장을 보내 주셔서 감사합니다. 나는 요구 사항을 가지고 있으며, 따라서 나는 이렇게했다. 구성 요소를 만들고 각각 최소, 최대 및 복원 버튼 3 개를 가져야한다. 최소 버튼을 누르면 아래로 내려와야하고 최대 버튼을 누르면 특정 프레임이 최소화되어 맨 아래에 최소 프레임이 표시됩니다. 이렇게하면 좋았습니다. 다른 방법이 있다면 그때 알려주십시오 –

답변

0

이 다음 해킹의 이상을 찾을 수 below.Please 코드를 발견하시기 바랍니다 사라지면 해결책.

이유는 무엇인지 모르겠지만 어떤 이유에서 데스크톱 창이 크기가 조정되면 다른 모든 구성 요소 (및 레이어 속성)에 관계없이 최대화 된 창이 맨 앞에 표시됩니다.

이것은 바탕 화면 창이 강제로 레이어 속성을 사용하는 것으로 보입니다.

public class DesktopPane extends JDesktopPane { 

    public DesktopPane() { 
     addComponentListener(new ComponentAdapter() { 
      @Override 
      public void componentResized(ComponentEvent e) { 
       revalidate(); 
       repaint(); 
      } 
     }); 
    } 

    /*...*/ 

} 
관련 문제