Can I avoid the state when components unexpectedly moved in container during design of GroupLayout?
Yes, actually you can minimize occurrence of this behavior when you keep the rules listed below.
- Have a concept of the designing form. It's better to have a relatively precise idea how the form will look like in advance. It's better to add components on the intended places directly, with the right (suggested) spacing and alignment, rather then throwing them randomly on canvas and then trying to rearrange them.
- Design by smaller parts. Try to divide complicated UI into sub-panels when suitable. You can then also switch (focus) design only to these individual panels. The visual design is easier to manage when composed from less complex parts.
- Alignment Tools. Use alignment tools from the designer toolbar in case when you want to center already placed components, align them along the left/right column etc - instead of rearranging them by mouse one by one.
- Guide Lines. Pay attention to the guidelines that appear when dragging components and use them to place/align/anchor components as needed. Snapping at guidelines creates relations between components which are preserved dynamically. Random positioning may lead to unexpected behavior later.
- Space Around Components. If you want to do small adjustments like moving components towards each other, which in fact means to adjust the space between components or at the border, use the "Space Around Components" dialog from the popup menu. It's much easier to set the desired space directly than trying to move multiple components manually.
- The Same Size Tool. To make several components of the same size, don't try to resize them to match each others size. Instead use the "Same Size" actions from popup menu on selected components.
Applies to: All NetBeans versions