Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which LayoutManager should I use?

Layout

Please see the image attached. I'm a beginner at Java GUI and was hoping someone could guide me in choosing a Layout Manager for GUI like this. I know I might have to use nested layoutmanagers, but I'm not sure which would help me accomplish this job.

like image 957
Faahmed Avatar asked Dec 26 '22 08:12

Faahmed


2 Answers

Here's an idea:

  • Use a BorderLayout in the main JPanel. Set the JList at the CENTER part
  • On the EAST part of the above layout, add a new JPanel with a GridLayout of 6 rows, 2 columns
  • On the GridLayout, add each of the labels, buttons, text fields, etc. in the same order as they're defined - from top to bottom and from left to right.

Alternatively: you could use a 7x2 GridLayout and fill the two positions above the buttons with empty text fields, to separate the labels/fields above from the buttons below.

like image 82
Óscar López Avatar answered Dec 28 '22 23:12

Óscar López


check out DesignGridLayout, it will be perfectly suited for this form I think

just look at their example:

enter image description here

with just a few lines of clean code:

    layout.row().grid(label("Last Name"))   .add(lastNameField) .grid(label("First Name"))  .add(firstNameField);
    layout.row().grid(label("Phone"))       .add(phoneField)    .grid(label("Email"))       .add(emailField);
    layout.row().grid(label("Address 1"))   .add(address1Field);
    layout.row().grid(label("Address 2"))   .add(address2Field);
    layout.row().grid(label("City"), 1)     .add(cityField);
    layout.row().grid(label("State"))       .add(stateField)    .grid(label("Postal Code")) .add(postalField);
    layout.row().grid(label("Country"), 1)  .add(countryField);
    layout.emptyRow();
    layout.row().center().add(newButton).add(deleteButton).add(editButton).add(saveButton).add(cancelButton);
like image 28
mantrid Avatar answered Dec 28 '22 22:12

mantrid