2014-05-11 5 views
-1

내가 200 행과 200 열 (하나 개의 픽셀에 대한 하나 개의 셀에 GBL를 사용하여 내 JPanel을 분할하려합니다. 어떤 생각을 어떻게 적절하게이 작업을 수행하는 방법을 분할. 코드는 나를 위해 작동하지 않습니다 아래에 배치했다.GridBagLayout에 JPanel의

JPanel pane = new JPanel; 
pane.setSize(200,200); 
GridBagLayout layout = new GridBagLayout(); 
layout.columnWidths = new int[200];  layout.rowHeights = new int[200]; 

나는 어떤 도움을 감사하게 될 것입니다.

답변

1

당신은. 그런 다음 사용하여 GBL 이러한 제약 조건을 적용 gridwidthgridheight 속성을 사용하여 각 픽셀의 크기를 설정합니다 GridBagConstraints 클래스를 사용할 수 layout.setConstraints(GridBagConstraints instance)

0

이런 식으로하면 목록이나 배열을 읽음으로써 픽셀을 변경하는 부분을 추가하면됩니다.

int y=0; 
int x=0; 
GridBagConstraints c = new GridBagConstraints(); 
c.fill = GridBagConstraints.BOTH; 

for(int stop=0;stop<=200;stop++){ 
c.gridx = ++x; 
c.gridy = ++y; 
pane.add(each_pixel, c); 
}