permaculture playing cards
The moose likes Swing / AWT / SWT and the fly likes Not understanding layouts in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Not understanding layouts in java?" Watch "Not understanding layouts in java?" New topic

Not understanding layouts in java?

John Corkrend
Ranch Hand

Joined: Oct 27, 2012
Posts: 51

Lately I have been testing different layout managers in java and none of them seem to make any sense to me. I understand the point of a layout manager, but I feel I can't get any of them to work properly. I'm coming from basic languages where you specified the position you wanted an element to go. I would like a layout manager that gives me complete control of my GUI without it being too difficult. Any tutorials or videos would be greatly appreciated, I have already looked at the Oracle help docs but it still isn't helping me.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2447
Start with the Swing tutorial. It has a section on using Layout Managers. Rarely would you use a single layout manager. Instead you would logically divide you GUI up into sub panels each which can use a different layout manager.

I'm coming from basic languages where you specified the position you wanted an element to go

The wrong approach when using Java. Layout managers do more than just position components on the screen.
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

You certainly can set the layout manager to null, and then specify the absolute positions of everything yourself. That doesn't really seem easier to me. Also, if you resize the window, then you have to write listeners to reposition everything to fit into the new space. That's really not fun. Could you be more specific about what's giving you trouble? Are some layout managers easier for you than others?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10819

For learning layout managers, the relevant section would be
Like Rob rightly said, the correct approach would be mix and match and nesting layouts. I have always thought of layouts as a sort of reverse jig saw puzzle. I know the complete picture (the UI design) and I try to break it down to known patterns (layouts)
I would suggest, you check out the provided link and identify what all patterns are available to you out of the box and then try to work your way back from your UI design. In case you get stuck you can always share your problem details here and we can help point you in the right direction.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
John Corkrend
Ranch Hand

Joined: Oct 27, 2012
Posts: 51

Ok well I will post back when I have a problem with a layout manager. I get frustrated when trying to implement one because I don't fully understand how to and exactly what to do. Thanks for the help.
I agree. Here's the link:
subject: Not understanding layouts in java?
It's not a secret anymore!