Spacing and Aligning Components

Spacers

There is a class that inherits from JComponent called Box. This is a lightweight class that uses BoxLayout as its Layout Manager. You can use this class to get at the convenience methods it makes available. These methods allow you to add invisible components to the layout that help you fit, position, and size the regions of your layout. Specifically, they help you do that by creating certain relationships between your visible control components.

We won't go into them in much depth. Suffice to say, here they are, here is what they're for, and go try them out for yourself to get the feel for them. This is the point in Swing programming that it becomes a little like learning to drive: eventually, you just ...

Get Java Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.