This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Best layout tutorials?  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Best layout tutorials?  " Watch "Best layout tutorials?  " New topic
Author

Best layout tutorials?

Sandeep Swaminathan
Ranch Hand

Joined: Apr 23, 2008
Posts: 52
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 !!


Music is all around us. All you have to do is just LISTEN to it,
Sandeep Swaminathan
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
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.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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 agree. Here's the link: http://aspose.com/file-tools
     
    subject: Best layout tutorials?