Layout Managers

Java uses a different philosophy to layout compared with tools such as Visual Basic or Delphi (if philosophy is not too grand an expression for laying out a program). Most design tools use an XY pixel based approach to placing a component. A component will effectively be placed X number of pixels from the left of the screen and Y number of pixels from the bottom of the screen. Thus in Visual Basic you can pick up a text box from the component palette and drop it at a location on a form, its location is set. If you then run the same program with a different screen resolution the components will retain their location rather than being adjusted to account for the screen size. If you run the program on a smaller screen it could be that the component will actually be “off the screen” and invisible. By contrast Java uses Layout classes to control where a component is placed according to the current screen.

Part of the reason for this is the cross platform nature of Java. A Java applet may display on anything from a palm top computer to a 19 inch Sun Workstation. I have tried writing Visual Basic applications that take account of more than one screen resolution and it is not a trivial activity. Be warned, if you have a background in other RAD tools you may find the Layout Manager approach a little weird at first.

Layout managers are generally used in combinations to almost "suggest" how an application should appear. Thus components have a default "preferred" size. Under one layout manager configuration they will be allowed to display at their "preferred" size, but under another they may be confined to a particular size, which may be influenced by the size of other components in the application.

Last modified: Sunday, 20 September 2015, 07:21 PM