What would be the best approach / LayoutManager for a JPanel that needed to display the components shown in the image? (Note that the fields should resize horizontally when the size of the window is changed, but not the labels).
I'm currently trying (and struggling) to do it with a GridBagLayout. Is this the correct approach or is there a better way? Should I be trying to divide + conquer the seperate sections maybe?
Any thoughts or advice would be gratefully appreciated. :-)
http://img261.imageshack.us/img261/2091/layouthb6.png
PS If you read this and there's no image, please bear with me whilst I fix it!
I would look at nesting JPanels
. It would be very easy to make each row a separate JPanel
and then just stack the JPanels
.
Otherwise you can use the GridBagLayout
. That is the one I use for more control over where components are placed.
Using GridBagLayout
you can layout a row by incrementing the GridBagConstraint
.gridx
and then resetting GridBagConstraint.gridx = 0
and GridBagConstraint.gridy++
to move to the next row.
I would suggest a third party free layout manager. MigLayout comes to mind (check the example form at the bottom of the linked page), or JGoodies FormLayout, which is especially good at formslike these.
The standard layout managers are good, but whoefully inadequate for frequent use for screens like these (the new GroupLayout used by the Matisse designer in Netbeans wasn't built for nothing). The linked layout managers are a lot easier to use and maintain IMHO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With