• Post Reply Bookmark Topic Watch Topic
  • New Topic

Suggested Layout for Simple Input

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just starting out with the varying layouts.
Figure a simple Login Dialog Box with 2 fields and 2 buttons.


Not concerned about hiding the password and this is just a simple exercise for producing a basic input window.

There is probably 1001 ways to do this but for something so generic and straight forward what is the most common layout used?

 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question.

Well you should need to know 1) JFrame (top level window) default layout is BorderLayout and 2) JPanel (where the content goes) default layout is FlowLayout.

You can override/change the component (JFrame, JPanel) default layout by setting the layout manager accordingly.

There are indeed many layout managers out there (Card, GrigBag, Box, Grid, etc).

Have a look at the tutorials here to understand more.

Personally I would use GridLayout for the 2 text fields and FlowLayout for the button. Hmm that's 2 layouts!
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, already viewed those topics.
I did figured multiple layouts would be required as there doesn't seem too many scenarios in which a single layout would work.

My current idea was something like the BorderLayout then place a FlowLayout at the bottom for the Buttons.

The biggest question pertains to the fields.
Would you create two more border layouts in the CENTER of the existing one with one for the Username label and field and another for the the password label and field?

I also suspect it best to make the window a fixed size to avoid adverse behavior with the labels, fields and buttons if it gets resized.
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Landry wrote:
My current idea was something like the BorderLayout then place a FlowLayout at the bottom for the Buttons.

The biggest question pertains to the fields.
Would you create two more border layouts in the CENTER of the existing one with one for the Username label and field and another for the the password label and field?

I also suspect it best to make the window a fixed size to avoid adverse behavior with the labels, fields and buttons if it gets resized.


Actually if you have too many panels will make yourself hard to follow (for maintain sake). Try out the GridLayout for the text fields. I'm sure it will make life easier than your planned approach.

For your last question, your can use the pack() method of the JFrame to fit everything into place (no excess space).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!