0

I'm trying to implement this GUI and I'm missing just a JTextField. I want it to be below everything, and as wide as the 2 comboboxes. Also add some height. I was trying to use it inside the GroupLayout (in the code below), but everything gets messed up if I do so. Is there a way of creating a new group layout underneath this one and just add the textfield? Thank you for your help

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);
user1803551
  • 12,965
  • 5
  • 47
  • 74
user3353167
  • 782
  • 2
  • 16
  • 31
  • 1
    1 hack to solve this is to add the current group layout (in a `JPanel`) to the `CENTER` of a `BorderLayout`. Add the new `JTextField` (possibly in another panel with another layout) to the `PAGE_END` of the `BorderLayout`. Of course, this will not work if the new text field needs to be *aligned* with any of the elements in the current `GroupLayout`. – Andrew Thompson May 08 '15 at 12:27
  • 2
    It should be pointed out that people *usually* consider `GroupLayout` to be a layout that must be used with a GUI builder (though a few brave souls hand code it). So for the most part, the advice is "keep it in the GUI builder for `GroupLayout` or learn how to create layouts by coding combinations of them". – Andrew Thompson May 08 '15 at 12:31
  • 2
    @AndrewThompson "*though a few brave souls hand code it*" You called? Seriously though, `GroupLayout` gets a lot of flak it does not deserve. Once you learn how to think about it, it's *somewhere between not at all and entirely* intuitive. – user1803551 May 08 '15 at 13:18
  • 2
    1) Do you want a text field on the bottom in addition to the one already at the bottom, and the new one spans the two comboboxes? 2) "*also add some height*" To what? Where? 3) Provide the definitions of the variables you use. I can guess them from the picture, but you really want to help me here. – user1803551 May 08 '15 at 13:21
  • the text box you see should be as wide as the window, and it should get a bit wider vertically too, that's what I meant – user3353167 May 11 '15 at 09:47

0 Answers0