在GUI中输入第二个组布局

时间:2015-05-08 12:24:53

标签: java swing layout-manager grouplayout

我正在尝试实现此GUI,而我只缺少JTextField。我希望它低于一切,并且与2个组合框一样宽。还要增加一些高度。我试图在GroupLayout(在下面的代码中)中使用它,但如果我这样做,一切都搞砸了。有没有办法在这个下面创建一个新的组布局,只需添加textfield?谢谢你的帮助

enter image description here

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    GroupLayout.SequentialGroup horizontalGroup = layout.createSequentialGroup();
    horizontalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jButton1)
            .addGap(50, 50, 50)

    ));

    horizontalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(fromLabel)
            .addComponent(timeLabel)
    ));

    horizontalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainLabel)
            .addComponent(queryLabel)
            .addComponent(employeeMsg)
            .addComponent(stopListDeparture)
            .addComponent(departureTime, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                  GroupLayout.PREFERRED_SIZE)
            .addComponent(jTextField)




    ));    
    horizontalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(toLabel)


    ));  
    horizontalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(stopListArrival)
            .addComponent(queryButton)

            .addGap(200, 200, 200)
    ));    
    layout.setHorizontalGroup(horizontalGroup);
    /////////////////////////////////////////////////////////////////////////////////////

    // creating the vertical view
    GroupLayout.SequentialGroup verticalGroup = layout.createSequentialGroup();
    verticalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addComponent(mainLabel)
            .addGap(50, 50, 50)
            ));
    verticalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)

            .addComponent(jButton1)
            .addComponent(employeeMsg)
            .addGap(50, 50, 50)

    ));
    verticalGroup.addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(queryLabel)
            .addGap(40,40,40)
    ));
    verticalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)



            .addComponent(jButton1)
            //.addComponent(jSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(fromLabel)
            .addComponent(toLabel)

            .addComponent(stopListDeparture)
            .addComponent(stopListArrival)
    );

    verticalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addComponent(departureTime, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                      GroupLayout.PREFERRED_SIZE)
            .addComponent(timeLabel)
            .addComponent(queryButton)

    );
    verticalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addComponent(jTextField)
    );
    layout.setVerticalGroup(verticalGroup);

0 个答案:

没有答案