A Java programs can be deployed on more than one platform. If you were to use standard UI design techniques of specifying absolute positions and sizes for your UI components, your UI might not look good on all platforms. What looks fine on your development system might be unusable on another platform. To solve this problem, Java provides a system of portable layout managers. Layout managers allow you to specify rules and constraints for the layout of your UI in a way that will be portable.
Layout managers give you the following advantages:
Correctly positioned components that are independent of fonts,
screen resolutions, and platform differences.
Intelligent component placement for containers that are dynamically
resized at runtime.
A Java UI container uses a special object called a layout manager to control how components are located and sized in the container each time it is displayed. A layout manager automatically arranges the components in a container according to a particular set of rules specific to that layout manager.
The layout manager sets the sizes and locations of the components based on various factors such as
the layout manager's layout rules
the layout manager's property settings, if any;
the layout constraints
associated with each component
certain properties common to all components, such as preferredSize, minimumSize, maximumSize, alignmentX, and alignmentY
In Java, certain types of containers use specific layout managers by default.
All panels (including applets) use FlowLayout.
When you create a container in a Java program, you can accept the default layout manager for that container type, or you can override the default by specifying a different type of layout manager.
Normally, when coding your UI manually, you override the default layout manager before adding components to the container. When using the Java Visual Editor, you can change the layout whenever you like. JDeveloper will adjust the code as needed.
JDeveloper's Java Visual Editor uses a default layout manager for each container, usually null layout. If you want to use a different layout manager than the default, you can do so by explicitly adding a layout manager to the source code for the container, or by selecting a layout from the container's layout property list in the Inspector.
Important: If you want to change the properties for a layout manager using JDeveloper's Java Visual Editor, you must explicitly specify a layout for a container so its properties will be accessible in the Property Inspector.
Choose a layout manager based on the overall design you want for the container. Some layouts can be difficult to work with in the Java Visual Editor because they immediately take over placement and resizing of a component as soon as you add it to the container. To alleviate this problem during initial layout prototyping, JDeveloper provides a default layout called null, which leaves the components exactly where you place them and at the size you specify. Starting with an null makes prototyping easier in your container. Later, after adding components to the container, you can switch to an appropriate portable layout for your design.
In some designs, you might use nested panels to group components in the main Frame, using various different layouts for the Frame and each of its panels.
Note:If you really want to design a panel without a layout manager, you can set the layout manager in the source code to null. However, you should not leave it this way for deployment.
Experiment with different layouts to see their effect on the container's components. If you find the layout manager you've chosen doesn't give you the results you want, try a different one, or try nesting multiple panels with different layouts to get the desired effect. See Using nested panels and layouts.
For a more detailed discussion of each layout, see the individual topics for each layout in Layouts Provided with JDeveloper. You can also study the Java Language Tutorial at this Sun Microsystems web page:
http://www.javasoft.com/nav/read/Tutorial/.
Copyright © 1997, 2004, Oracle. All rights reserved.