Fixing the Layout

The arrangement of the components still looks rather ugly. The easiest way to fix that is to set the sizes and positions of all components by hand. This approach is simple but has several drawbacks:

For that reason the layout in Java can be defined with the help of layout managers, which implement different general layout strategies and adapt dynamically to new situations. Consult a standard textbook on Java to learn about the properties of the different possible layouts. If you are only interested in beans in the context of the PhysBeans library, you may skip this section, because the layout of PhysBeans applets is fixed by templates, which are provided by the library.

  1. As an intermediate step to simplify the following rearrangement, change the global layout of the applet to FlowLayout: All components change their positions and posssibly their sizes, everything is completely mixed up.
  2. Add a JPanel bean (icon of jPanel) from the palette. It shows up as a small empty blue square. If you click anywhere in the form window, it apparently disappears, but a click on its entry in the inspector window makes it visible again.
  3. Put the plus button into this panel:
  4. Similarly put the other three buttons into jPanel1. Instead of using the inspector window you can move icons directly in the form window. In this case the bean is represented by a blue dotted rectangle and a surrounding panel by a grey dotted rectangle. Look at at inspector window to make sure that all buttons are actually inside the panel. The form now looks like
  5. Add another panel (jPanel2) und put the first label and the first text field into it. The result should be:
  6. Repeat the last step twice to put the other labels and text fields together into jPanel3 and jPanel4.
  7. Add a last panel (jPanel5) and put the three subpanels (jPanel2, jPanel3, jPanel4) into it. This can probably be done best in the inspector window, if you hide the internal parts of the subpanels by clicking at their open icon icon.
  8. Configure the layouts of the panels:
  9. Fix the global layout of the applet:
  10. Change the global size of the form:
  11. Polish the layout:

This finishes the graphical user interface of the demo applets, it looks like