Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Layout opinions  RSS feed

 
Manny Ruiz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have gotten a lot of help and great tips from you guys over the course of these last few weeks, but I have a question. On multiple occasions I have been advised not to use a null layout for mu programs. Now that I have a little extra time to look into other types of layouts, I have to ask which ones are better? Is there a layout that is most commonly used? Which one is the easiest to learn?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manny Ruiz wrote:...I have to ask which ones are better? Is there a layout that is most commonly used? Which one is the easiest to learn?

The answer to better and commonly used would be...depends.
The answer to easiest to learn would be, again depends..on how smart you are

From my experience, I usually end up using a combination of layouts. Remember, layouts can be nested. When I started learning Swing, I used to draw the UI design on paper, and then try to break it down into patterns Bunch of components in a horizontal row. Or a bunch of columns in a vertical stack. I would outline those component groups and that would give me an idea of what layout to use. I still use this method. Only difference is instead of paper, I have learnt to visualize it in my mind.

The API docs are very helpful. The offer you information on tweaking the layouts. Alignment, gaps etc. If you want to get used to layouts, I would suggest keep the API handy. In fact, API is helpful for almost all code you write. It is a good habit to cultivate.

I know people are terrified of the GridBagLayout. I feel thats mostly because of the hype concerning it. Even before you start learning it, you are told its complicated.
Nothing doing. Well yes maybe. But like everything else, once you get a hang of it, its just like any other layout.

You might also want to google for MigLayout. It is relatively easy to use. My personal gripe is it does no have constraint constants (last time I checked anyway).

Layouts are extremely useful. It is worth investing time in learning them.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote: . . . I know people are terrified of the GridBagLayout. . . .
If you go to Cay Horstmann's website, you can find out about the GBC class, which makes GridBag a lot easier to use. There are more details about GBC in Horstmann's book. That same page also gives a link to the classic GridBag tutorial
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote: That same page also gives a link to the classic GridBag tutorial

Ah yes. I was googling for this but couldn't find it.
Thanks Campbell.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Whether Manny Ruiz will thank us, is a different question . . .
 
krillian konstatos
Ranch Hand
Posts: 49
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i prefer to use GridBagLayout when it comes to layout form components for user input like textfields and comboboxes, buttons etc. it took me a very long time to learn how it works but when
i got more comfortable with it am totally depending of it. but one of the downsides i have discovered is that it is to fall into complex form deisgns which has happened to
me lately. i know you can solve this by using nested panels but i am very stubborn so i add my components over one panel only with the method
add(JComponent, GridBagConstraints) in the JComponent class like the one listed below ...



this could be done easier in many ways but for me the above example is the best.
and i have found out that it is worth to spend a lot of time on learning how to use
the GridBagLayout class. I am very glad that i did this.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!