tags:

views:

131

answers:

4

I'm not sure how it is using other frameworks but this questions is strictly regarding Java swing.

Is it better to use a Visual Editor to place objects or to manually code the placement of the objects onto the frame (Layout managers or null layouts)?

From my experience I've had a lot of trouble using Visual editors when it comes to different screen resolutions or changing the window size. Using manual code to place objects I've found that my GUIs behave a lot better with regard to the screen size issue. However when I want to change a small part of my GUI it takes a lot more work compared to using a visual editor

Just wondering what people's thoughts were on this?

+1  A: 

Personally i use layout managers over visual editors, the result is more readable, maintainable code. Also, you're not tied to any specific visual editor which may change (or stop being supported).

Dimitar
+2  A: 

You need to develop skill with both: one will always be faster than the other for some particular task. Having said that, without some manual skill, a designer will slow you down.

trashgod
+4  A: 

I never use a visual builder for my Swing UIs.

The ease to build a new UI generally becomes a pain point during software maintenance: some builders can't easily modify existing screens (in particular if they have been manually modified for some good reason); imposing a GUI builder to the people in charge of maintaining your software generally also means imposing their IDE as well, people may lack productivity if they have to use an IDE they are not used to or, worse, that they don't like.

Of course, manually building UIs comes at a cost: understanding the complexity of various LayoutManagers. However, there is a broad range of Swing LayoutManagers out there (mostly open source), some being both easy to use (and maintain) and powerful.

Two examples:

  • DesignGridLayout will work for all forms-like windows and is not only easy to use (less than 1h to understand and use) but also enforces good looking UIs and is the only one (that I am aware of) where you can "visualize" the shape of your UIs by just reading the java code.
  • MigLayout is more powerful, but a bit more complex to use and it won't prevent you to design ugly UIs ;-)

One additional point: NEVER use absolute position/size in your UIs, this is looking for problems (your UIs may be truncated on some monitors/systems...)

jfpoilpret
Well actually I've had a lot of success using absolute position/size in regards to the placement of JPanels compared to using a layout manager. I've tested it with different systems/monitors/screen resolutions. The key is to calculate all locations and sizes based on the current screen size.
Albinoswordfish
But sometimes this is not enough to do so: you need to account for screen resolution too (with latest HDPI screens you may have problems), the size of the system fonts (chosen by the end user), and last but not least, you have to think about i18n... So in the end, in the best case, you never truncate anything, but you have some wasted and ugly white space where it is not needed.
jfpoilpret
Does layout managers also take into account system font sizes?
Albinoswordfish
No, but PLAF do, and LayoutManagers use components methods (min size, pref size, max size, baseline, inter-component gaps...) which get some of their information based on PLAF.Regarding HDPI monitors, some PLAF also integrate this information but not all.
jfpoilpret
+1  A: 

I personally have used over the years a lot of GUI designer - in Eclipse, NetBeans, IntelliJ. And I was never happy with the restrictions that they imposed and the code that they generated. In the end I had so much custom tweaks that using the designers hindered my work instead of assisting it. And then I found MigLayout - for me this piece of software is Godsend. It managed to take out the unneeded complexity out of my Swing labs and let me design superb layouts with minimum efforts. I don't think that MigLayout is harder to use(as someone above mentioned) - it's certainly to harder to use than CSS.

Even if you don't like MigLayout, my advice is to stay away from GUI designers. A simpler alternative of MigLayout is JGoodies Forms Layout(which MiG supercedes), jide-oss features some nice simple layouts as well. If you want to use a designer, however, my advice would be - IntelliJ IDEA Forms designer + JGoodies Forms - imo it generates much more maintainable code then say NetBeans Matisse.

Bozhidar Batsov