Working with Rows and Columns Begin | Previous | Next
Setting Default Properties for a Columns and Rows | Alternating Row Colors | Sorting | Ensure a Row is Visible | Row Height | Column Width | Column Name

Setting Default Properties for a Columns and Rows
In addition to or instead of setting properties on individual cells you can also set the default properties for a columns and rows. This means that any cell in that row or column will be rendered with that property. Any property set on the column can be overriden by a property set on a row. Both of these can be overriden by setting the same property on the cell.

An additional advantage to using default properties for rows and columns is that it uses less resources on large sets of data. This is especially useful when using the virtual DsResultSetModel which only needs to load a small portion of a query which may contain to 2 billion records. Setting the properties on each individual records would take a lot of processing time and memory.

grid.getCellAt( 1, 2 ).setForeground( );
grid.getRowProperties( 1 ).setForeground( Color.magenta );
grid.getColumnProperties( 1 ).setForeground( Color.cyan );
grid.getColumnProperties( 2 ).setForeground( );
Alternating Row Colors
The background of adjascent rows can be made automatically painted a different color. The two colors can be specified and are alternated as each row is painted. Another call can additionally set the foreground colors.
grid.setAutoStyle( DsGrid.ALTERNATING_ROW_COLOR );
The foreground color can also be specified in addition to the background color.
grid.setAutoStyle( DsGrid.ALTERNATING_ROW_COLOR,
         , Color.white, Color.white, Color.lightGray );
Sorting is built in and available for any model. You have control over the sort order, column, and whether the user can click on a column to change the sort column and order.

The defaults are ascending sort order, sort column = 0, NumClicksToSort = 0, and Sorted = false.

grid.setSortOrder( DsGrid.DESCENDING );
grid.setSortColumn( 1 );
grid.setNumClicksToSort( 1 );
grid.setSorted( true );
Ensure a Row is Visible
Scroll to make sure a certain row is visible on the screen.
grid.ensureVisible( row );
Row Height
Setting the row height is provided by the base JTable implementation. The row height can be set for the entire grid or on an individual row by row basis.
grid.setRowHeight( 30 );
grid.setRowHeight( 1, 20 );
Column Width
A convenience method on DsGrid has been implemented which calls the base JTable implementation in the column model to change the width of the specified column.
grid.setColumnWidth( 1, 20 );
Column Name
A convenience method on DsGrid has been implemented which sets the text displayed in the column header.
grid.setColumnName( 1, "one" );
Copyright 2003 Diamond Edge, Inc. All rights reserved.