Building GUI using GroupLayout in Java

前端 未结 1 523
不思量自难忘°
不思量自难忘° 2021-01-03 01:48

I need to build a GUI using GroupLayout (not other layouts). The GUI will look like the following:

----------------------------
| field 1  field 2  field 3 |         


        
1条回答
  •  囚心锁ツ
    2021-01-03 02:23

    Fixed some parantheses and added resizing hints for components:

    layout.setHorizontalGroup(layout
        .createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(one, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(two, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(three, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addGroup(layout.createSequentialGroup()
            .addComponent(four, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(five, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addComponent(six, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    
    layout.setVerticalGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(one).addComponent(two).addComponent(three))
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(four).addComponent(five))
        .addComponent(six));
    

    enter image description here

    0 讨论(0)
提交回复
热议问题