• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Can't figure out which layout to use

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic