• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't figure out which layout to use

 
Tom Trelty
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edited to add: I am using the card layout to switch between different panels, so I am trying to nest a certain layout within this card layout.

Hello,

I am trying to make a GUI that looks something like this:



I basically want a bar along the top that is invariant in size, and then components below that bar that may vary in size and be positioned in a a symmetric manner. In this picture, I have username and password text boxes in the center, and then below those there are buttons for login and registration.

I tried using the GridBagLayout and my issue was that because of the weighty component, the panels of my GUI would get stretched relative to the size of other components and look ridiculous. I tried nesting gridbaglayout pieces and I managed to break it even further.

I tried using a borderlayout panel with gridlayout panels nested inside, and I experienced the stretching behavior again.

I've since deleted my gridbaglayout code(it made me pull my hair out), but I will include my current code and a picture of what it produces (notice how the text boxes stretch).





Lines 60-122 are the important ones



I really don't want to use a "third party" layout, since I'm sure what I want is possible to achieve but I can't figure out how!
Any help would be greatly appreciated in achieving independently sized panels!
 
Rob Camick
Ranch Hand
Posts: 2668
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I basically want a bar along the top that is invariant in size, and then components below that bar that may vary in size and be positioned in a a symmetric manner.


So you use the default BorderLayout of the JFrame.

Then to the BordLayout.PAGE_START, you add a panel containing the fixed size components.

Then to the BorderLayout.CENTER you add the panel using the CardLayout. Then each card you add to this panel you use the relevant layout manager or use nested panels with different layout managers.

You are never restricted to use a single layout manager for the frame.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic