2013-12-23 8 views
0

2 행 3 열로 GridLayout Frame을 만듭니다. 첫 줄과 각 칸에 3 개의 JLabel을 넣었습니다. 내가 실행하려고 할 때, 세 번째 레이블은 두 번째 행과 왜 발생합니까GridLayout의 구성 요소가 제대로 표시되지 않습니다.

screenshot

아래 표와 같이 첫 번째 열에입니까? 여기

은 전체 세포 당신이에 구성 요소를 추가 할 때 (수직/수평)과,이 행 하나 먼저 장소 구성 요소 하나를 배치로 구성 요소를 resise GridLayout 사용하기 때문에 발생하는 코드

JFrame windows = new JFrame("Shop"); 
    windows.setLayout(new GridLayout(2,3)); 
    JLabel prodlabel = new JLabel("Products"); 
    windows.add(prodlabel); 
    JLabel spacelabel = new JLabel(" mid "); 
    windows.add(spacelabel); 
    JLabel shoplabel = new JLabel("Shopping List"); 
    windows.add(shoplabel); 
    windows.setSize(1360, 728); 
    windows.setVisible(true); 
+0

는'Box'를 사용하여, 그것은 적절한 사이즈를 유지합니다. _box_를 사용하는 방법을 보려면 ['Answer Answer] (http://stackoverflow.com/a/20737349/2587435)를 참조하십시오. –

답변

1

행과 열이 모두 0이 아닌 값으로 설정된 경우 GridLayout의 동작 방식과 관련이 있습니다. LayoutManager는, 행수 및 컨테이너의 컴퍼넌트 수에 근거 해, 열수 자체를 결정합니다.

대신 행 수를 0으로 설정하고 열을 3으로 설정할 수 있습니다. LayoutManager는 컨테이너에 더 많은 구성 요소를 추가 할 때 행을 더 추가합니다.

windows.setLayout(new GridLayout(0,3)); 

편집 : 말씨, 그리고 here's a link to the Java Tutorial on GridLayout which may or may not have more information related to the matter.

0

행이 가득 차면 행을 전환합니다. 다른 LayoutManager을 사용해야합니다. 예 : GridBagLayout

또는 행 new GridLayout(1,3)을 사용하여 수정할 수 있습니다.

0

6 개의 요소에 대한 레이아웃을 설정합니다. 실행시 6 개의 요소를 모두 추가하려고 시도하십시오.

관련 문제