我正在做一个学校项目,需要布局方面的帮助,因为它正在做一些时髦的事情。
我只需要南面板的帮助。南面板的组织方式如下:
JRadioButton JLabel1 JLabel2
JRadioButton JLabel1 JLabel2
JLabel3--------JTextField----------JButton
我尝试过以下方法:
- 将南面 JPanel 设置为 3 行网格布局
- 另一个 JPanel 也具有网格布局,其中 3 行添加到网格布局的第一行。
- 对第二行和第三行重复#2。第二行有 3 行 x 3 列。
- 在适当的行/列中添加了组件。
没有按照我需要的方式格式化。我尝试过一些我不记得的其他技术。有什么建议么?谢谢。这是南面板的外观图片:http://www.freeimagehosting.net/image.php?d14a73db5e.jpg
它从“开始日期...”开始
最佳答案
创建一个新的 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...
尝试一下。
关于Java - GridLayout 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2075909/