Java - GridLayout 问题

标签 java grid-layout

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

我只需要南面板的帮助。南面板的组织方式如下:

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

我尝试过以下方法:

  1. 将南面 JPanel 设置为 3 行网格布局
  2. 另一个 JPanel 也具有网格布局,其中 3 行添加到网格布局的第一行。
  3. 对第二行和第三行重复#2。第二行有 3 行 x 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/

相关文章:

html - 响应式网格布局 - 仪表板样式 - 100% 高度和宽度的容器

java - JFrame - 在 GridLayout 中设置行和列

java - 使用 FlowLayout 管理器将 3 个面板保留在不同的行中

java - 如何在 @Scheduled 注释中指定 PST 时区,该注释应在太平洋标准时间上午 7 点到下午 6 点之间每小时触发一次?

java - 当盒子不够大时,面板会相互重叠

java - 部分填充的实体对象并在更新期间保持数据一致

java - 我可以创建没有 svg 文件的 JSVGCanvas 吗?

java - 将递归方法变成迭代方法

java - 用于输出棋盘格的按钮的 GridLayout

css - Bootstrap 2 - 网格列环绕行为是否与 Bootstrap 3 相同?