1

I am trying to design a simple gui interface. The frame consists of a main panel which contains another four panels "Staff Details", "Job Details" "Photo" and buttons. The output is as follows:

output

I used gridLayout for all the panels except for the "buttons panel" which has borderLayout.

Now I want to reduce the height of the bottom two panels so it won't have the extra space. How do I do that?

Here is the code for the "photo" panel and "button" panel. Both panels now have flow layout.

        photoPanel.setPreferredSize(new Dimension(300,70));
        photoPanel.add(browsebx);
        photoPanel.add(browseBtn);


        btnPanel.setPreferredSize(new Dimension(300,70));
        btnPanel.add(addBtn);
        btnPanel.add(editBtn);
        btnPanel.add(deleteBtn);
        btnPanel.add(cancelBtn);
Charlie
  • 3,113
  • 3
  • 38
  • 60

2 Answers2

1

you can use this.

jPanel.setPreferredSize(new Dimension(x, y));

jPanel.setMaximumSize(new Dimension(x, y));  
jPanel.setMinimumSize(new Dimension(x, y));
Dyrandz Famador
  • 4,499
  • 5
  • 25
  • 40
1

Your main panel is using a GridLayout, which means all four panels will be the exact same size. Don't use a GridLayout.

Instead maybe you can use a GridBagLayout. This allows your to add each panel to a specific grid, but each panel will maintain its preferred size as determines by the layout manager used on each of the individual panels.

Read the section from the Swing tutorial on How to Use GridBagLayout for more information and examples.

Remember each of the 4 child panels can use a different layout manager if desired. For example you would probably want to use a FlowLayout for the buttons panel.

camickr
  • 321,443
  • 19
  • 166
  • 288