NetBeans Quick Tip #30 - When GroupLayout Fails



Usually you'll do pretty well for most of the GUIs with GroupLayout (the default layout manager used in Matisse). But there are some GUIs for which it's not really suitable. I learned that today after several hours of fighting with Matisse. An example of a GUI you don't want to create with GroupLayout is the one I created today.

The problem is that with GroupLayout components group together and if you want to position them really freely, they snap even if you don't want them to snap. And then if you add one more component, it just moves all the other ones and you're screwed.

So, a solution which I found for this type of complex GUIs with background and exact 1-pixel position requirements is to use AbsoluteLayout:


With AbsoluteLayout you can place things quite precisely. The GUI won't resize properly, but that doesn't matter in my case. Now comes the Big HackTM: when you are ready with the form you can convert the GUI from AbsoluteLayout to GroupLayout (actually it's called Free Design in the menu). Then you don't need the AbsoluteLayout library, because the GUI is back in GroupLayout. Now you can fine tune things (move them by 1px etc.) And if you're lucky, you can even add a component without breaking the rest of the form :)

I also realized that it's possible to design multi-layered GUIs with Matisse by using jLayeredPane. The trick when designing each of the panels is to choose "Design this container" and then you can move the components easily in the panel (without disturbing the rest of the form or the background). So by dividing your form into many layers with jPanels you can actually create very complex and very good looking GUIs. It would be great to have better support for such design though, e.g. moving components by arrow keys would be really awsome!
Comments:

Post a Comment:
Comments are closed for this entry.
About

Roman Strobl

Search

Archives
« duben 2014
PoÚtStČtSoNe
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today