Yes. Place the two button panels in a top panel. Use vertical layout for the content pane. Add the top panel and the result panel.
Box
Layout managers sometimes jam components together
in a way that makes the layout look cramped.
The class Box
can help in this situation.
A Box
object is a container similar to a panel,
but lacking some features.
The default layout manager of Box
is BoxLayout
.
The previous example programs could be re-written using Box
in place of JPanel
.
This would slightly simplify the code since it would rely on the
default BoxLayout
manager rather than specifically setting it.
However, the most useful features of class Box
are
its methods that create invisible components.
These components correspond to rectangular areas of the screen.
They are used as spacers to separate the visible components.
If you have ever set type you know how useful spacers are in
creating an attractive page.
To create a fixed-sized invisible component use the method:
Box.createRigidArea( new Dimension( int width, int height ) )
The parameter to createRigidArea()
is a Dimension
object,
which does little more than hold a width and a height.
(Software Design Question:) Is it wise to use integer literals for
width
and height
?