java swing 中怎么使控件换行
2个回答
展开全部
使用GridBagLayout,大致这样:
GridBagLayout
gridbag
=
new
GridBagLayout();
GridBagConstraints
c
=
new
GridBagConstraints();
setLayout(gridbag);
c.fill
=
GridBagConstraints.BOTH;
c.weightx
=
1.0;
gridbag.setConstraints(c);
add(new
Button("button1"));
c.gridwidth
=
GridBagConstraints.REMAINDER;
//这是本行的最后一个
gridbag.setConstraints(c);
add(new
Button("button2"));
c.weightx
=
0.0;
//重新开始一行
gridbag.setConstraints(c);
add(new
Button("button3"));
GridBagLayout
gridbag
=
new
GridBagLayout();
GridBagConstraints
c
=
new
GridBagConstraints();
setLayout(gridbag);
c.fill
=
GridBagConstraints.BOTH;
c.weightx
=
1.0;
gridbag.setConstraints(c);
add(new
Button("button1"));
c.gridwidth
=
GridBagConstraints.REMAINDER;
//这是本行的最后一个
gridbag.setConstraints(c);
add(new
Button("button2"));
c.weightx
=
0.0;
//重新开始一行
gridbag.setConstraints(c);
add(new
Button("button3"));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询