Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 541
Ciaran Avatar asked Feb 12 '09 21:02

Ciaran


People also ask

What is GroupLayout?

GroupLayout is a LayoutManager that hierarchically groups components in order to position them in a Container . GroupLayout is intended for use by builders, but may be hand-coded as well. Grouping is done by instances of the Group class. GroupLayout supports two types of groups.

What is MiGLayout in Java?

MiGLayout is a grid-based layout underneath, as is FormLayout or GridBagLayout. However, it provides constraints that allow it to be used conceptually as a flowing or docking layout; it even provides absolute positioning of some components.


2 Answers

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.

like image 153
David Z Avatar answered Sep 21 '22 15:09

David Z


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.

like image 44
Michael Myers Avatar answered Sep 19 '22 15:09

Michael Myers