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

 

Column and Row Sizes

There are a variety of ways to define the sizes of columns and rows.

Absolute and Scalable Space

The total width of the container is called the total width. The sum of the widths of all columns allocated an absolute pixel size is called the absolute width. The total width minus the absolute width is called the scalable width.

Columns specified with an absolute width are absolute columns. Columns specified with percentages are called scalable columns. There are also fill columns and preferred columns which are specified with the FILL and PREFERRED TableLayout constants, respectively.

A preferred column has an absolute width that is just large enough to ensure that all components contained partly or wholly in that column have their preferred with. For example, if a column contains two buttons, one with a preferred size of 80x25 and the other with a preferred size of 50x25, the column will have a width of 80 pixels.

Order of Allocation

The total width of a container is first allocated to absolute columns and preferred columns. The remaining width, the scalable width, is then allocated to the scalable columns. If the sum of the scalable columns is less than 100%, there will be some scalable width left over. This scalable width is then divided equally among all the fill columns. Consider the following sizes.


        double size[][] =
            {{100, 0.50, 0.20, TableLayout.FILL, 200, TableLayout.FILL},
             {TableLayout.FILL};
                

Let's say the container is 500 pixels wide. The column widths will be

Column 0 100 pixels
Column 1 100 pixels
Column 2 40 pixels
Column 3 30 pixels
Column 4 200 pixels
Column 5 30 pixels

The total width is 500 pixels. The absolute width is 300 pixels. The scalable width is 200 pixels. The scalable columns add up to 70% leaving 30% to be divided between two fill columns each getting 15%.

Rounding Considerations

One of the uses of TableLayout.FILL is to absorb rounding errors when rows or columns are given relative sizes. If you specify one or more columns with a relative width, it is a good idea to have at least one FILL column.

Previous | Next