I am in the process of completing a course work but I need some help understanding this:
“Note: Your application should keep the relative positioning of buttons and checkboxes
when the frame of the application is resized based on the layout managers and the tech-
niques covered in the module. I.e. you should not choose absolute coordinates when
placing JComponents on the screen but relative positioning, i.e. component X is to the
right of component Y and to the left of component Z and these relative locations should
be maintained if the user resizes the frame of the application.”
Does this mean im not to use BoxLayout.X/Y_AXIS? Absolute coordinates?
To my understanding I have to use several panels? If so, my code contains a login and when I login how will I change the colour of the frame?
There’s basically two ways to layout the components in a JFC/Swing application:
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
PreferredSizeof the JComponents; for example, aFlowLayoutwill 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_AXISandBoxLayout.Y_AXISare 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!