2011-04-09 9 views
0

솜 단추가있는 패널을 만들고 있습니다. this is what it looks like now.격자 바깥 쪽 세로 틈

하지만 버튼이 서로 닿기를 원합니다. 즉, 수직 간격이 사라지기를 원합니다. 그러나 단추 크기를 조정하면 안됩니다. 어떻게해야합니까?

내 코드 : 사전에

this.setLayout(new GridBagLayout()); 
    GridBagConstraints constraints = new GridBagConstraints(); 

    constraints.fill = GridBagConstraints.HORIZONTAL; 
    constraints.gridwidth = 2; 
    constraints.weightx = 1D; 
    constraints.weighty = 1D; 
    constraints.gridx = 0; 
    constraints.gridy = 0; 
    int row = 0; 
    for (MainAction actie : mainActions) { 
     constraints.gridy = row; 
     row++; 
     SelectedActionButton but = new SelectedActionButton(selectedActionModel, actie); 
     this.add(but, constraints); 

    } 
    constraints.gridwidth = 1; 
    constraints.weightx = 0.5D; 
    row *=2; 
    for (AbstractAction actie : objectActions) { 
     constraints.gridy = row/2; 
     constraints.gridx = row%2; 
     row++; 
     SelectedObjectButton but = new SelectedObjectButton(selectedObjectModel, actie); 
     but.setMargin(new Insets(0, 0, 0, 0)); 
     this.add(but, constraints); 
    } 

감사

답변

1

변경 문제가 해결됩니다

constraints.weighty = 0D; 

에 다음 줄

constraints.weighty = 1D; 

.

업데이트 : 모든 버튼을 정렬 북쪽 가능한 모든 공간을 먹고 마지막 행에서 추가 구성 요소를 추가 할 수 있습니다 : D 단지 하나의 문제를 지금 방법 : 좀 작동하는 것 같다

constraints.weighty = 1D; 
constraints.gridy = row; 
this.add(Box.createGlue(), constraints); 
+0

yups 오, 버튼이 북쪽인지 확인할 수 있습니까? 사기꾼들은 지금 센터에있다 – Drareeg

+1

@ user545236 가능한 북쪽 해결책은 내 편집을 참조하십시오. – Howard

관련 문제