Note on Layout Managers with pack()

Because Java is "write once, run anywhere", you need a flexible GUI.

Indeed, a rigid design which looks good on one platform might look awful on another with different screen size and resolution. Also it would be nice if a Java program had the look and feel that a user is used to.

Playing with layout managers

You can play around with various layout managers using the following applet.

LayoutDemoApplet

This applet can pop up a number of frames (windows) which lay out various components for a unit conversion program.

Three layout managers are illustrated:

These layout managers are shown interacting with the pack() method that is provided in the class Window.

Source code of all frames.

On-line Tutorial: How to Make Frames (Main Windows)