gpt4 book ai didi

Java - GridLayout 问题

转载 作者:行者123 更新时间:2023-11-30 07:38:16 25 4
gpt4 key购买 nike

我正在做一个学校项目,需要布局方面的帮助,因为它正在做一些时髦的事情。

我只需要南面板的帮助。南面板是这样组织的:

           JRadioButton JLabel1 JLabel2
JRadioButton JLabel1 JLabel2
JLabel3--------JTextField----------JButton

我尝试了以下方法:

  1. 将南 JPanel 设置为 3 行的网格布局
  2. 另一个 JPanel 也有一个网格布局,其中 3 行添加到网格布局的第一行。
  3. 对第二行和第三行重复#2。第二行有 3 行 3 列。
  4. 在适当的行/列中添加组件。

没有按照我需要的方式进行格式化。我尝试了一些我不记得的其他技术。有什么建议么?谢谢。这是南面板应该是什么样子的图片: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com