frusDev
frusDev

Reputation: 1978

GroupLayout: Is it worth learning?

I'm relatively new to java (specifically swing) and have recently been making some fairly simple applications, learning as I go. The latest one has lots of form components such as JLabels, JTextFields, JButtons, etc etc. All were placed in NetBeans using a visual builder. I have to say I'm not really taking to NetBeans and have really just been designing the GUI and copying the code straight to Eclipse.

My question is: Is it worth getting a very good understanding of GroupLayout and coding by hand (and therefore having more control over my GUI) or just continuing on as is?

Upvotes: 10

Views: 7503

Answers (5)

L.Sankaranarayanan
L.Sankaranarayanan

Reputation: 1

If you are inclined to a VB Program Style you spend time on GroupLayouts. Otherwise try to understand GridBagLayout Manager with suitable examples. It is the best for those who want every gui component should be under our pen control(We should write and not the IDE). A good java developer should spend time in gui objects and business objects and must know how to separate them. L.Sankaranarayanan.

Upvotes: 0

Erick Robertson
Erick Robertson

Reputation: 33068

GroupLayout is worth learning to use programmatically.

I use GroupLayout as my default layout on nearly every panel I create which uses standard Swing components. I find that the results are always very pleasing to the eye and resize very well. I always set these options:

groupLayout.setAutoCreateGaps(true);
groupLayout.setAutoCreateContainerGaps(true);

Using this layout repeatedly has not only given me great-looking layouts, but it gives me the low-level experience required to be able to put together some complicated panels with a number of components that is unknown at compile time. I also find, when the number of components is dynamic, that I can lay out all the components and then turn them on and off with setVisible(boolean) without recreating the horizontal and vertical groups.

Upvotes: 3

jtplumber
jtplumber

Reputation: 27

Most of the more complicated layout managers are not meant to be hand-coded. You can do it, but you'll likely have trouble understanding your own layout a few months from now. GroupLayout is no exception, worse it's not intuitive at all, you have to contort your mind forcing your layout into GroupLayout terms.

It's my opinion that these layout managers are not worth learning. GridBagLayout is the worst of all. It has more options than you can possibly figure out, and they never seem to do what you think they do. MiGLayout is very powerful, reasonably intuitive, and mostly does what you think it does, but I'll still argue that it's too powerful and too complicated for its, and the programmer's own good. GroupLayout is not as powerful, not as intuitive, and not worth the trouble.

My advice from years of laying out Java GUI and maintaining them is to learn and use the most powerful layout manager you can master in two hours and that you'll never forget, then layout your GUI with nested containers using this layout manager and the basic BorderLayout/GridLayout/FlowLayout/BoxLayout.

Upvotes: 1

David Z
David Z

Reputation: 131570

I'd say it's worth taking some time to understand GroupLayout if only because it's always a good idea to understand what your IDE is doing. Knowing what goes on behind the scenes actually makes you more flexible, because if you wind up in a situation where you don't have access to Netbeans, you'll know how to replicate the layout it would have produced for you. Besides, after you've gotten a decent amount of experience, you'll probably wind up saving time overall. You can often develop a simple GUI faster by hand than by using a visual editor, especially considering the time it takes you to copy and paste the code from Netbeans to Eclipse.

And of course, learning how to use GroupLayout by hand will also make it easier for you to transition to any of the other layout managers Java offers, which in turn can lead to simpler code and even more time saved.

Upvotes: 11

Michael Myers
Michael Myers

Reputation: 191895

GroupLayout wasn't really designed for hand-coding; it's much, much more verbose than any other layout manager (except possibly GridBagLayout). Since you say you're new to Swing, I suggest starting with the basic layout managers (BorderLayout and FlowLayout); you can use them in NetBeans by right-clicking the panel or frame and choosing "Set Layout". After you're familiar with those, I suggest you check out MiGLayout.

To answer your other question: I think of NetBeans form designer as similar to a calculator; it's a wonderful tool if you already know the basics, but you'll never learn anything if you just use it as a crutch.

Upvotes: 10

Related Questions