Search code examples
javaswinglayout-managergridbaglayoutborder-layout

GridBagLayout or BorderLayout for proposed project in Swing/AWT?


I'm attempting to create a GUI as pictured:

enter image description here

I'm having some trouble deciding which layout would be the best for this.

I've attempted to use a GridBagLayout, but can't figure out how to make items different sizes, and how to position them.

I've also considered using a BorderLayout and creating an eastpanel, westpanel and centerpanel these using the respective layout constraints to put them there, but this feels incorrect.

I've also read the how to use GridBagLayout Java tutorial, but still can't figure out how to achieve the goal.


Solution

  • You should not force yourself to use only a single panel with a single layout. Nest several panels inside each other with each panel possibly having different layouts.

    You could have 1 root panel with a BorderLayout. For the top you have a panel with a FlowLayout (or maybe a gridbaglayout). And the center can be another panel with a GridBagLayout or perhaps a combination of more nested panels.

    There is no one magic layout that can do everything. Composition is the key.