go to previous page   go to home page   go to next page


Yes ... usually you would use arithmetic expressions that use the current size of the frame to calculate a pleasing size for the spacers.


You want the spaces in your design to expand or shrink in proportion to the size of the frame. A fixed-sized component is inflexible. All GUI components have a getSize() method that is used to determine the dimensions of the component. The dimensions may change as a program executes, so this is a useful method. To determine the current size of a frame, use:

Dimension JFrame.getSize()

Then look at the height and width fields of the Dimension object. Use that data to create a rigid area of appropriate size. If this is too complicated, then use glue.

The glue component is another invisible component that class Box creates. Think of glue as stretchy caulking between components. It keeps them separated, but expands or shrinks as needed.

To create glue use one of the following:



How is a glue component added to container such as a frame?