我正在做一个学校项目,需要帮助布局,因为它正在做一些时髦的东西。
我只需要南方小组的帮助。南面板的组织方式如下:
JRadioButton JLabel1 JLabel2
JRadioButton JLabel1 JLabel2
JLabel3--------JTextField----------JButton
我尝试了以下内容:
不格式化我需要它的方式。我已经尝试了一些我不记得的其他技术。有什么建议?谢谢。这是南面板应该是什么样子的图片:http://www.freeimagehosting.net/image.php?d14a73db5e.jpg
从“开始日期......”开始
答案 0 :(得分:3)
为此创建一个新的JPanel
并使用Group Layout。
Like this http://img163.imageshack.us/img163/1403/capturadepantalla201001bo.png
使用组布局允许您指定将进入水平组的组件以及将进入垂直组的组件。
c1, c2, c3
c4, c5, c6
panel[ c7, c8, c9 ]
以下是我如何布置上面的图片:
// Layout Horizontal components
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent( c1 )
.addComponent( c4 )
).addGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent( c2 )
.addComponent( c5)
).addGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent( c3 )
.addComponent( c6 )
)
);
// Layout vertical components
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent( c1 )
.addComponent( c2 )
.addComponent( c3 )
).addGroup(
layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent( c4 )
.addComponent( c5 )
.addComponent( c6 )
)
);
southPanel.add( panel ); // the start-end dates
southPanel.add( bookIt, BorderLayout.SOUTH ); // the enter your name...
试一试。
答案 1 :(得分:1)
我要为南JPanel做的是使它成为1x3网格,然后将第一行的三个组件添加到水平Box中并将其添加到网格中,然后将第二行的三个组件添加到另一个水平Box中并将其添加到网格中,然后将第三行的三个组件添加到3x1网格中并将其添加到网格中。然后,您可以通过添加各种胶水和支柱组件来调整前两行的精确外观。
通过将jpanels或Boxes放在其他布局中,我实现了大部分布局。这使您可以很好地控制自己想要的内容,并允许您一次构建一个部分。
答案 2 :(得分:0)
看起来你想要一个GridLayout,其中3个列,而不是3个行,用于底部面板。
在您包含的链接的图像中,文本字段比JLabel或按钮宽。您可能需要尝试使用GridBagLayout。
答案 3 :(得分:0)
最近我偶然发现了MigLayout,我会尝试在我的下一个大学项目中使用它,我建议你试一试它看起来真的很酷很简单。