2016-12-04 5 views
0

저는 잠시 동안 JPanels를 사용하고 있으며 이제 다른 JPanel 위에 JPanel을 배치하려고합니다.다른 JPanel 상단의 JPanel

나는 JLayer를 사용하여 보았지만 궁금해했습니다. 아래쪽과 위쪽의 레이어를 설정하는 솔루션이 있다면 가능한 경우 각 구성 요소 레이어를 설정하고 싶지 않습니다.

JPanel bottomPanel = new JPanel();  # Set as bottom panel 
JPanel topPanel = new JPanel();   # Set as top panel 
JPanel sidePanel = new JPanel();  # Don't have to set 
JPanel anotherSidePanel = new JPanel(); # Don't have to set 

는이에 대한 최선의 해결책이 무엇인지 할 수없는 경우, 감사합니다.

+0

하는 ASCII 아트 또는 간단한 도면을 제공 * 구성 * 최소 크기의 GUI의 레이아웃, 그리고 더 폭, 경우 크기 조정 및 신장. –

답변

2

메인 패널에 BorderLayout을 사용할 수 있습니다. 그것은 레이아웃 매니저입니다 당신이 원하는 같은 소리

mainPanel.add(leftSide, BorderLayout.LINE_START); 
mainPanel.add(rightSide, BorderLayout.LINE_END); 
JLayeredPane lp = new JLayeredPane(); 
mainPanel.add(lp, BorderLayout.CENTER); 
+0

와우,'JLayeredPane'과 같은 것이 있다는 것을 결코 알지 못했습니다. 고마워요! –

2

: 같은

그럼 당신은 뭔가를 할 수 있습니다. 다른 요구에 맞는 몇 가지 다른 것들이 있습니다. 이 게시물의 하단에 링크가 있습니다.

개인적으로 가장 좋아하는 프로그램은 GridLayout입니다. 당신이 원하는 무엇을위한 그래서, 당신은이 작업을 수행 할 수 있습니다 당신이 원하는 것을 할 것입니다

JPanel panel = new JPanel(); 
panel.setLayout(new GridLayout(2, 1)); 
//the first number is the number of rows, the second is the number of columns 

JPanel topPanel = new JPanel(); 
JPanel bottomPanel = new JPanel(); 
panel.add(topPanel); 
panel.add(bottomPanel); 

합니다. 당신이 그들에 대한 자세한 내용을 원한다면

가 여기 링크입니다 : Oracle Docs on Layout Managers