views:

37

answers:

3

I'm developing a GUI application rapidly using a GUI buidler (Netbeans). I am frustrated with the Swing widgets... when I resize one the rest seem to "reorganize" themselves in the wrong places.

What do you guys use to tame such chaos? I was thinking of tables.... but couldn't find any in the Netbeans Palette.

Regards

+2  A: 

Use MigLayout.

If you want to use pure Swing, use GridBagLayout and be prepared for a lot of pain.

Aaron Digulla
I see. It looks like I have to hand code the layout. So, I'm assuming that "drag and drop" Swing in Netbeans does not work for big GUI projects?The most efficient way is to use a layout manager, no?
Carlo del Mundo
NB should support visual editing of GridBagLayout but then, I do all my UI manually as well. It's just more simple in the end: I can define a couple of helper methods which build the UI the way I want with a few lines of code and when I need to change something, I know what happens.
Aaron Digulla
+1  A: 

You are never forced to use a single layout manager. That is the problem with using an IDE to design a GUI. You get bloated code because the tool uses a single layout manager with multiple confusing constraints in order to get the form layout out the way you drag and drop it.

Create your forms manually and use nested panels with different layout managers to layout the components as desired. The code is easier to maintain and understand.

camickr
Does your answer imply to simply drop using an IDE? I am totally fine with this.... if this is the case, why do we even bother with GUI builders apart from it's rapid development?
Carlo del Mundo
IDE's provide more benefits then simply designing a form. They are great for debugging and so on, but I don't like to use them to generate code. The code is not portable between IDE's and you end up spending more time learning how to do something in the IDE rather than learning Java which can be applied in all environments.
camickr
+1  A: 

Coding GUI manually should be the preferred way (at least for the sake of maintainability). There are a few, open source, Swing layout managers that are pretty good at it.

Someone has mentioned MigLayout, which allows any layout, is quite simple to use, but often requires some tweaking until you get what you want.

On the other hand, you also can use DesignGridLayout, which is suitable for most common layouts and is easier to use (thanks to its fluent API) than MigLayout.

jfpoilpret