TableLayout

Java Technology Home Page
Downloads, APIs, Documentation
Java Developer Connection
Docs, Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide


TSC Contents
Front Page
Article Index

Related Links
JFC Home
Download J2SE
J2SE 1.4 Release
Notes for Swing
Java Tutorial
Java Web Start
Swing Sightings

Sign up for email
notification

 

 Article Table of Contents 
    
 Introduction 
  What is TableLayout? 
  Creating a TableLayout 
    
 Column and Row Sizes 
  Absolute and Scalable Space 
  Order of Allocation 
  Rounding Considerations 
    
 Cells 
  Adding Components 
  Justification 
  Multiple Cells 
    
Final Theory 
  Dynamic Rows and Columns 
  Preferred Layout Size 
  Onward 
    
 Examples 
  Simple 
  GridLayout Comparison 
  GridBagLayout Comparison 
  A Typical GUI 
  Preferred Rows and Columns 
  TableLayoutConstraints 
  A RAD Tool 
    
 API Reference 
 Download 
Help pagesA-Z Index

The Source for Java Technology

 

Final Theory

Some final details to consider.

Dynamic Rows and Columns

As in a spreadsheet, rows and columns can be added at any time. Components are moved down and to the right as necessary. Rows and columns can also be removed or resized at runtime. The TableLayout class has methods to accomidate this.

Preferred Layout Size

One of the responsibilities of a layout manager is to determine the preferred size of a container based on the container's components, the component's constraints, and the layout manager's configuration. The preferred size of a container is typically the size that will allow all components to be at least as large as their preferred size. When frame.pack is called, the frame's layout manager is asked to determine the frame's preferred size, and that size is given to the frame.

TableLayout uses a complex algorithm to determine the preferred layout size. The entire algorithm is beyond the scope of this article, but the fundamental idea behind the algorithm is to add the preferred sizes of all rows and columns to arrive at the container's preferred size. The preferred size of a column is fixed if the column is given an absolute size. For scalable, fill, and preferred columns the preferred width is determine by the column's percentage or fill/prefer attribute and the preferred widths of all components contained either partly or wholly in the column. Since a component can ocuppy many scalable columns and a single column can contain many such component, the preferred size can be tricky to determine.

However, the final behavior is simple. Any component in an absolute column will be given an absolute width. Any component partly or wholly in a scalable, fill, or preferred column will be given a width equal or greater than its preferred width. The component will be given a greater width only if necessary to ensure that another component is given its preferred width.

Layout managers also must be able to compute the minimum size of a container, which is typically the size the container must be to ensure all of its components are at least the size defined by their getMinimumSize method. The minimum size of a container is determined almost the same way that the preferred size is determined.

Onward

Now that we've covered the theory behind TableLayout, let's move on to some examples.

Previous | Next