Using null layout

Layout managers help control the size and position of all components in a container. In containers using null layout, each component defines its own bounds to determine size and location.

About this task

The visual editor provides grid markers that help you visually align components, and you can snap components to the grid. When you set to null the layout for an existing container that was previously using a layout manager, the Design view does not change in appearance. The visual editor calculates and sets the bounds for each component using the setBounds() method.

Procedure

Example

Tip: You can start with the layout manager set to null and then change to a layout (like the GridBagLayout) to get the constraint settings calculated by the visual editor for Java™. The advantage of having each component control its bounds is that you can be sure that a component is always the same size and in the same position at run time. The disadvantage of having fixed size and height is that the components does not adjust their bounds if the application is resized by the user. In addition, labels on components such as buttons or check boxes need to change size based on font or locale.

Feedback