2014-05-11 31 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

您可以使用GridBagConstraints類,設置使用gridwidthgridheight性能每個像素的尺寸,然後再用申請這些約束你的GBL 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); 
} 
相關問題