This lab exercise will give you practice creating and laying out Swing containers. You will take a class that produces a component that looks like:

and modify it to look like:

The zipped NetBeans project to use for this lab is here: CS_2511_Layout_Management.zip.

Unzip the project folder and open the resulting CS_2511_Layout_Management project in NetBeans.

Run the LayoutManagement.java file and verify that it works. It should produce a frame laid out like the first applet in the lab Overview.

Note that clicking on a button causes the button's label to be displayed in the far right of the frame.

You will modify the layout_management.LayoutManagement class shown below.

  • The background color for the buttons is CYAN
  • The background color for the bordered labels is PINK
  • The size of the buttons is 125 × 25 pixels
  • The size of the bordered labels is 125 × 50 pixels
  • The vertical gap between buttons and labels is 5 pixels
  • The horizontal gap between columns of components is 20 pixels
  • Each column of components is vertically centered in the display area
  • There is an empty border at least 10 pixels wide surrounding the whole component
  • The FlowLayout, BorderLayout, and GridLayout layout manager classes are in the java.awt package
  • FlowLayout, BorderLayout, and GridLayout have constructors allowing the setting of horizontal and vertical gaps between components
  • The BoxLayout layout manager class is in the javax.swing package; however, since you can't set horizontal and vertical gaps it is not very useful for this lab
  • You can achieve the effect of a vertical BoxLayout using GridLayout
  • Some layout managers do not respect the component dimensions given through the setPreferredSize method, instead stretching their components to fit the overall size of the container. There are two ways to deal with this:
    • Use the java.awt.GridBagLayout layout manager, which is not described in our text; while flexible and powerful, it is more complex than the other layout managers
    • Wrap the components in another JPanel. For example, if you have a panel of buttons, create another "wrapper" panel, add the panel of buttons to it, and use the wrapper panel
  • The easiest way to vertically center a component is with FlowLayout
When finished, zip your project folder as your-login-LEX6.zip.

Email the zip file to your TA.

  • Correct behavior: 3 points
  • Correct appearance and layout: 7 points