Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not understanding layouts in java?

 
John Corkrend
Ranch Hand
Posts: 51
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2584
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For learning layout managers, the relevant section would be http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html
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.
 
John Corkrend
Ranch Hand
Posts: 51
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic