2014-05-11 32 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); 
} 
相关问题