This topic describes the use of tables within IBM Director.
Tables are easier to read if the background is lightly-striped. This is especially true if the table contains a large number of rows or columns.
The IBM Director framework provides a table cell renderer that will color the foreground and background of a component to use lightly-striped colors defined in IBM Director's LookAndFeel class. If the component is an instance of JComponent, it will be set opaque. The table cell renderer class might be subclassed to provide more customization as shown in Example 1 and Example 2.
Developers who want to modify existing cell renderers to use striped backgrounds might use the following property values defined in IBM Director's LookAndFeel class:
These color values might be obtained using UIManager.getColor() as follows:
UIManager.getColor("Table.background");
UIManager.getColor("Table.alternateBackground");
UIManager.getColor("Table. editableBackground");
UIManager.getColor("Table. editableAlternateBackground");
The following example is a table cell renderer for numeric values that are to be right-justified. The renderer can customize an object and then submit it to the super class to have the background and foreground colors applied.
import com.tivoli.twg.guilibs.TWGTableCellStripedBackgroundRenderer
private class MyTableRenderer extends TWGTableCellStripedBackgroundRenderer
{
private JLabel jl = null;
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
if( value instanceof JLabel )
{
jl = (JLabel)value;
jl.setHorizontalAlignment( SwingConstants.RIGHT );
}
else if (value instanceof String)
{
jl = new JLabel( (String)value );
}
else
{
jl = new JLabel();
}
// The super class will color return the label. Both the foreground
// and the background will be set appropriately based on the
// isSelected value.
return super.getTableCellRendererComponent(table, jl, isSelected,
hasFocus, row, column);
}
}
Example 1 can be modified so that numeric values are displayed in a different color.
import com.tivoli.twg.guilibs.TWGTableCellStripedBackgroundRenderer
private class MyTableRenderer extends TWGTableCellStripedBackgroundRenderer
{
private JLabel jl = null;
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
if( value instanceof JLabel )
{
jl = (JLabel)value;
jl.setHorizontalAlignment( SwingConstants.RIGHT );
}
else if (value instanceof String)
{
jl = new JLabel( (String)value );
}
else
{
jl = new JLabel();
}
// The super class will color return the label. Both the foreground
// and the background will be set appropriately based on the
// isSelected value.
jl = (JLabel) super.getTableCellRendererComponent(table, jl, isSelected,
hasFocus, row, column);
// set the forground color to the special numeric display color
jl.setForeground( TWGConsoleColor.getBlueColor() );
return jl;
}
}
Table row heights are set to 16 by JTable. This height does not work well with the range of font sizes that will be required to satisfy accessibility requirements in IBM Director Version 5.1. Row heights should be set based on font size and must be reset if the UI changes while the table is visible.
The updateUI method of the framework's table widget is overridden to ensure that its row height is adjusted every time the UI is modified:
public void updateUI()
{
// Tables fix their row heights at 16 by default. This does
// not accommodate all font sizes nor does it allow for
// the correct spacing for characters in Japanese, Korean, and Chinese.
// A slightly larger size works better for them.
String lang = Locale.getDefault().getLanguage();
JLabel label = new JLabel();
FontMetrics fm = getFontMetrics( label.getFont() );
int rowHeight = fm.getHeight() + 2;
if ( lang.equals( "ja" ) || lang.equals( "ko" ) || lang.equals( "zh" ) )
rowHeight += 5;
setRowHeight( rowHeight );
// Be sure to update the super class super.updateUI();
}