0

I'm trying to create a basic GUI for booking classes in a gym. I'm not very familiar with the grid layout and struggling with creating a 2 column grid.

Here's what I'm trying to achieve: Gym layout

And here's my grid code so far:

private void createPanel() {
    
    setLayout(new GridLayout(4, 1));

    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    JPanel panel3 = new JPanel();
    JPanel panel4 = new JPanel();
    
    //Panel 1: member ID field
    panel1.add(memberIDLabel);
    panel1.add(memberIDField);

    panel1.add(courseNameLabel);
    panel1.add(courseNameField);
    
    panel1.add(bookButton);
    
    //Panel 4: 'view courses' and 'view members' buttons
    panel4.add(coursesButton);
    panel4.add(bookingsButton);
    
    //Attaches panels to frame
    this.add(panel1);
    this.add(panel2);
    this.add(panel3);
    this.add(panel4);
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Lylio
  • 5
  • 6
  • Help with what? What doesn't this do that you want it to do? Don't make us guess your question. – arcy Nov 12 '17 at 16:38
  • A 2 column `GridLayout` obviously has 2 in the second parameter of the `GridLayout` constructor? – Dabiuteef Nov 12 '17 at 16:43
  • And you should probably use `GridBagLayout` for this task. Cells in `GridLayout` are forced to have same size. – Dabiuteef Nov 12 '17 at 16:47

0 Answers0