GroupLayout: Is it worth learning? [closed]
Asked Answered
S

5

10

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?

Sear answered 12/2, 2009 at 21:56 Comment(0)
H
11

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.

Hassiehassin answered 12/2, 2009 at 22:44 Comment(1)
I'm thinking this too; I may be in a situation where I don't have the convenience of copying code from NetBeans but where I need to make a relatively complex GUI -- and in the cases where I need to make a simpler GUI, I need not turn to NetBeans, rather build it on a simpler layout manager.Sear
E
10

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.

Ensanguine answered 12/2, 2009 at 22:33 Comment(2)
I think SpringLayout is even more verbose. ;) I've used the GroupLayout that comes with LWUIT and it was not too bad, but not easy either. I liked JGoodies FormLayout, and since MiG Layout is its successor, I warmly recommend MiG. Anyways, it's good to know also the basic layouts.Amoy
I am already familiar with BorderLayout - but practically GroupLayout is what I think is best for the application I'm currently building. As for using NetBeans as a crutch - I merely don't like the IDE and find it needlessly over-complicated in some partsSear
A
3

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.

Aalii answered 24/11, 2011 at 14:34 Comment(0)
E
1

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.

Ending answered 13/2, 2009 at 3:53 Comment(2)
-1 GroupLayout seems very intuitive to me. Sure, it's verbose, but this is Java we're talking about. Just read the documentation, and follow this example. After that, start using it on "real life" GUI projects. I think you'll find it's really not as bad as it looks at first.Bukovina
-1 I agree with @bcat. I would also like to take direct issue to the advice in the last paragraph. The best results always come from mastery that takes longer than two hours. I will never forget how to use GroupLayout as long as I keep using it. I also don't understand how GroupLayout could possibly be any more complicated than using nested containers. This is how I'd do it if someone told me to make it complicated.Aalii
K
0

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.

Kinghood answered 16/12, 2012 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.