• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best layout tutorials?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well well when it comes to layout I'm always confused which one to use! People say GRIDBAGLAYOUT is the best but the examples used are so damn confusing that I'm not able to implement them
Is there a better example for gridbaglayout? Or shall I use any other layout? I have developed a code and there's a screenshot attached too which is what the output is supposed to look! Suggest me friends

Thanks !!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using GridBag you need a trip to Cai Horstmann's website (or the appopriate chapter of his book) to learn about his GBC class. It makes using GridBag much easier. He quotes this tutorial, but some people think it's a spoof.

Google for MigLayout; I have never used it, but I have heard it is easier to use than GridBag.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know many (myself included) who avoid using GridBagLayout unless absolutely necessary. Most layouts can be set up by using the other managers and by nesting JPanels.

By the way, I couldn't find your link.

Edit: also,

  • You might want to avoid calling JFrame#show() as it has been deprecated. Instead call JFrame#setVisible(true);.
  • You'll want to call pack(); before setVisible(true) as this will tell your layout managers to do their laying out.
  • You'll only want to call these methods after you've added your widgets into your GUI. If you do it otherwise (like I see now), your GUI will be blank until it is manually resized.
  • Avoid using setSize(...) but instead use setPreferredSize(....), and use it relatively sparingly. Most layout managers respect the preferred size, not the size.
  •  
    I don't like that guy. The tiny ad agrees with me.
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic