

The constructor for BoxLayout is a little unusual. The BoxLayout manager places each of its managed components from left to right, or from top to bottom in the order that they are placed in the container. I will provide an illustration of nesting JPanel objects using BoxLayout in a subsequent lesson. You can nest containers having a BoxLayout manager to achieve groupings of horizontal and vertical lines of components. Therefore, a group of components in a horizontal or vertical line will remain in the line when the container is resized. The components do not wrap (as in FlowLayout). While BoxLayout is the default layout manager for a Box container, it can also be applied to other containers as well, such as JPanel.īoxLayout is a layout manager that makes it possible to position components in either a horizontal line or in a vertical line. As a result, many capabilities imparted by the JComponent class (such as the creation of borders) do not apply to a Box container. One shortcoming of Box as a container is that it does not extend JComponent. I will discuss the use of these invisible components in a subsequent lesson. These invisible components are very useful for controlling the appearance of component layouts in containers that use BoxLayout. While the Box class can be used as a container, perhaps its most useful characteristic is serving as the home for several class methods that produce invisible components: (For example, attempting to cause the layout manager for a Box to be FlowLayout produces the following runtime error: : Illegal request. Unlike other containers, however, you cannot modify the layout manager of a Box object. The Box class can be used to produce a lightweight container that uses a BoxLayout (see below) object as its layout manager.

I will discuss a number of characteristics of each, and will show you some screen shots that illustrate the use of the BoxLayout manager. In this lesson, I will introduce you to the Box container and the BoxLayout manager.

The lessons listed above will introduce you to the use of Swing while avoiding much of the detail included in this series.
#Flowlayout java align left series
This series is intended for those persons who need to understand Swing at a detailed level. This series of lessons entitled Swing from A to Z, discusses the capabilities and features of Swing in quite a lot of detail. We may make money when you click on links to our partners. content and product recommendations are editorially independent.
