I am coding a contact list application in eclipse using Java Swing.
How can I get a simple table layout that contains just columns and rows?
I don’t want row or column labels.
Something like this:
first name: john
middle name: franklin
last name: doe
Where the names would be editable text boxes etc.
What’s the best component to use?
I will also have buttons below the text fields.
Currently I have a JFrame which is running correctly. It pulls up a window that has my menu options correct. But when I try to do this:
myFrame.setLayout(new GridLayout(6, 2));
I get an error. I would like to have a grid layout of two columns and 5 rows (maybe 6).
I want to have a label on the left column, and a text box on the right column.
then two buttons at the bottom, centered.
You’d better of breaking your fields and controls (buttons) into separate panels, this allows you to supply different layout managers for each.
I’d start with a base
JPanelusing aBorderLayout.Onto this, I’d add the “fields” panel at the
CENTERposition and the controls (buttons) at theSOUTHposition.For the fields, I’d use a
GridBagLayout, but I’m picky like that, and for the controls panel I’d probably use aFlowLayout(unless you have access to a niceButtonLayoutmanager ;))This means you could end up with something like
UPDATED with code sample