There's basically two ways to layout the components in a JFC/Swing application:
- assign each container a layout manager that will take care of the layout; see the link provided by @Shakedown
- assign each JComponent an absolute position for it's top left corner, counting pixels from the top left starting at (0,0) of the top-level-container (see here for what that is) the components are in; see this tutorial on absolute positioning.
As you can imagine, the second way has some problems: it's not at all dynamic and is easy to get wrong, to name the most prominent ones. Using a layout manager in most cases is not only the easier, but also the smarter way to arrange your GUI.
What the layout manager in effect does is assign each JComponent an absolute position derived from the layout the component is layed out by at runtime, dynamically - usually using the PreferredSize
of the JComponents; for example, a FlowLayout
will assign each JComponent an absolute position that will put it exactly fitting to the right of the JComponent before it, wrapping lines when needed. When a container is resized, all components within it will have their positions recomputed. See here for details.
Concerning your question about BoxLayout
, that is a layout manager; BoxLayout.X_AXIS
and BoxLayout.Y_AXIS
are used to determine in which direction the JComponents which the BoxLayout manages are to be arranged; they do not refer to absolute positioning. See the Javadocs on BoxLayout and the Java tutorial on BoxLayout for details.
All in all, your task is to use a layout manager; the different layout managers that are available in the standard java libraries are described in sufficient detail in the tutorials (see links, browse the sites). Have fun!