3
Programming JClass LiveTable Pro

Property Summary · Visible Rows/Columns · Frozen Rows and Columns

Row and Column Labels · Table Titles · Row Height and Column Width

Cell and Label Margins · Foreground, Background and Shadow Colors

Cell and Label Text Alignment · Cell and Label Fonts

Border Types and Sides · Images · Text and Image Clipping

Cell and Label Spanning · User Data


Property Summary

The following figures summarize all of the JClass LiveTable Pro properties. It is not necessary to remember all the properties to program JClass LiveTable Pro effectively. For most tables, many properties may be left at their default settings.

Each of these properties have two accessor methods: set and get. Methods are instantiated using set(PropertyName), and you can retrieve the current value of any property using the property's get method.

Table-wide properties
AllowCellResize Specifies how an end-user is able to interactively resize rows/columns.
ColumnLabelOffset Specifies the spacing between the column labels and the cell area in pixels.
DisplayClipArrows Specifies whether or not to display clipping arrows when the value of a cell/label value cannot be fully displayed.
DoubleBuffer Controls whether or not double-buffering is used when displaying and updating the table.
FrameBorderType Specifies the type of border for the frame surrounding the cell and label areas.
FrameShadowThickness Specifies the thickness of the frame shadows surrounding the cell and label areas.
FrozenColumnPlacement Specifies the location of all frozen columns within the component display.
FrozenColumns Specifies the number of columns from the start of the table that are not horizontally scrollable.
FrozenRowPlacement Specifies the location of all frozen rows.
FrozenRows Specifies the number of rows from the start of the table that are not vertically scrollable.
JumpScroll Controls scrolling behavior. Scrollbars can "jump scroll" by whole rows/columns.
LeftColumn Indicates the non-frozen column at least partially visible at the left side of the window.
MarginHeight Specifies the distance (in pixels) between the inside edge of the cell border and the top and bottom edge of the cell's contents.
MarginWidth Specifies the distance (in pixels) between the inside edge of the cell border and the left/right edge of the cell's contents.
MinCellVisibility Specifies the minimum amount of a cell that is made visible when edited.
Mode Specifies the display mode.
NumColumns Specifies the current number of columns in the table
NumRows Specifies the current number of rows in the table.
Repaint Specifies the screen display refresh value.
RepeatBackgroundColors An array of colors to be used when a Background value is JCTblEnum.REPEAT_ROW or JCTblEnum.REPEAT_COLUMN.
RepeatForegroundColors An array of colors to be used when a Foreground value is JCTblEnum.REPEAT_ROW or JCTblEnum.REPEAT_COLUMN.
RowLabelOffset Specifies the spacing between the row labels and the cell area in pixels.
SelectedBackground Specifies the background color of selected cells.
SelectedCells Specifies an array of currently-selected ranges of cells.
SelectedForeground Specifies the foreground color of selected cells.
SelectedBackground Specifies the background color of selected cells.
SelectedCells Specifies an array of currently-selected ranges of cells.
SelectedForeground Specifies the foreground color of selected cells.
SelectionPolicy Specifies the selection behavior allowed on the table, both by end-users and by the application.
ShadowThickness Specifies the thickness of the shadows surrounding each cell and label.
Spans Specifies an array of currently-spanned ranges of cells or labels.
TopRow Specifies the non-frozen row at least partially visible at the top of the window.
TrackCursor Specifies whether the mouse pointer should be tracked as the user moves the mouse across the table.
ValidatePolicy Specifies when to validate changes to cell or label values against their data types (specified by DataType).
VisibleColumns Specifies the number of columns currently visible or partially visible.
VisibleRows Specifies the number of rows currently visible or partially visible.


Cell-only properties
Cell Specifies a cell value.
Cells Specifies the cell values.
DataType Specifies the data type of a cell/label value. When set, this property affects cell and/or label value changes from that point on.
Editable Specifies whether cell values can be changed by an end-user.
MaxLength Specifies the maximum number of characters that can be entered in a cell by a user.
Multiline Specifies whether or not a user can enter multiple lines of text into a cell.
Traversable Specifies whether the cell can be traversed to.


Cell/Label properties
Alignment Specifies the alignment of the cell/label text and/or image.
Background Specifies the background color of cells and labels.
BorderSides Specifies the sides of a cell or label that display the border type in their border area.
BorderType Specifies the style used for cell and label borders.
CharHeight Specifies the number of lines of text that a row can display.
CharWidth Specifies the number of characters that a column can display.
Component Used to add Java AWT components, strings, JCStrings or images in an individual cell or label.
Font Specifies the font to be used to display cell and/or label values.
Foreground Specifies the foreground color of cells and labels.
PixelHeight Specifies the row height in pixels.
PixelWidth Specifies the column width in pixels.
StringCase Specifies the case of cell values of cells edited by the user.
UserData Specifies a user data object that the application can attach to a cell.


Label-only properties
ColumnLabel Specifies a column label.
ColumnLabels Specifies all the column labels.
ColumnLabelOffset Specifies the spacing between the column labels and the cell area in pixels.
ColumnLabelPlacement Specifies the position of the column labels relative to the cells.
ColumnLabelSort Specifies whether a column is sorted when its label is clicked.
RowLabel Specifies a row label.
RowLabels Specifies all the row labels.
RowLabelOffset Specifies the spacing between the row labels and the cell area in pixels.
RowLabelPlacement Specifies the position of the row labels relative to the cells.
RowLabelSort Specifies whether a row is sorted when its label is clicked.

Number of Rows/Columns

The NumRows and NumColumns properties set the number of rows and columns in the table. They must be set for most tables because they define the size of the table shown to the user.

These properties are independent of the Cells structure that stores the cell values. NumRows/NumColumns can be smaller or larger than the number of rows/columns in the table's cell values structure, as shown in the following figure.

Using setNumRows() to limit number of scrollable rows

For example, you could temporarily "delete" rows from the bottom of the table by reducing the value of NumRows. The rows could be restored later by increasing NumRows.

The number of rows/columns must be greater than the number of frozen rows/columns. For more information on frozen rows/columns, see Frozen Rows and Columns.


Visible Rows/Columns

The number of rows and columns currently visible in the window is specified by VisibleRows and VisibleColumns.1

These properties are dynamically updated as other table properties change and when a user interacts with the component.

You can force the table to display a particular number of rows or columns by setting these properties. Setting visible rows/columns always causes the table to attempt to resize itself, overriding the resize policy set by AllowResize.

You cannot set the number of visible rows or columns to greater than the corresponding NumRows and NumColumns properties.

Displaying the Entire Table

To display the entire table, set VisibleRows and VisibleColumns to zero. Setting either property to zero sets a special flag that causes it to attempt to resize to display all rows/columns in the table. Any change to the number of rows/columns in the table will cause the table to attempt to resize when this flag has been set.


Frozen Rows and Columns

An application can make rows and columns non-scrollable using FrozenRows and FrozenColumns. FrozenRows specifies the number of rows held at the top or bottom of the window and not scrolled. FrozenColumns specifies the number of columns held at the left or right side of the window and not scrolled.

Frozen rows/columns always start from the beginning of the table. They are still editable and traversable unless set otherwise. The following figure shows an example of frozen rows.

Visible and Frozen Rows and Columns

Use frozen rows/columns to hold important information (such as totals at the bottom of the table) on the screen as a user scrolls through the table. Another use is as additional rows/columns that act like labels.

Freezing Rows and Columns

To freeze rows/columns, call moveRows() or moveColumns() to move the desired rows/columns to the beginning of the table. Then set FrozenRows or FrozenColumns to the number of rows/columns that you want to freeze.

For example, the following code moves row 5 to the beginning of the table, and then freezes it:

 
     table.moveRows(4, 1, 0);
     table.setFrozenRows(1);

Frozen Row/Column Placement

You can place frozen rows at either the top or bottom of the table. Frozen columns can be placed at either the left or right of the table. The placement of frozen rows/columns does not affect the location of the rows/columns in the cells.

To change the placement of the frozen rows, set FrozenRowPlacement to either PLACE_TOP or PLACE_BOTTOM.

To change the placement of all frozen columns, set FrozenColumnPlacement to either PLACE_LEFT or PLACE_RIGHT.


Row and Column Labels

Row labels are set by using RowLabels, and column labels are specified by using ColumnLabels. Row/column labels are stored separately from the cell values. Users cannot interactively edit labels. Text within a label can be left-justified, right-justified, or centered. Individual labels can be set using setColumnLabel() and setRowLabel().

Note that setColumnLabels() and setRowLabels() does not affect the number of rows and columns a table displays.

Setting and Retrieving Label Values

Setting All Labels

To specify all of the labels for a row or column, set ColumnLabels or RowLabels to a new list of labels, as shown by the following example:
     String clabels[] = { "Name", "Address",
"Phone Number", "Position", "Salary" };
...
     table.setColumnLabels(clabels);

Setting Individual Label Values

To set individual labels, specify the particular label and set any attributes you want to set for that label. If you wanted to set a particular label to the color red, you would use the following code:
  
     setColumnLabel (3, 56, Color.red)

Retrieving a Label

Use getLabel to retrieve the value of a label or labels, as in the following example:
 
     Vector v2 = table.getColumnLabels();
     for (int i = 0; i < v2.size(); i++) {
          Object o = v2.elementAt(i);
               System.out.println(     }

Label Placement and Spacing

Label Placement

You can specify the positioning of row/column labels on the screen using ColumnLabel and RowLabel in conjunction with values derived from JCTblEnum. Valid values include: The next figure displays the effect of reversing the default row/column label placement.

Reversing the default row/column label placement

Label Spacing

Normally, there is no space between labels and the cell area. The RowLabelOffset property specifies the distance in pixels between the row labels and the cell area. Similarly, the ColumnLabelOffset property specifies the distance in pixels between the column labels and the cell area. If a negative value is specified, the labels overlap the cell area.

Row and column label spacing


Table Titles

An application can add one or more titles to any side of a table. A title is a component that is outside of the table's cells and labels. Once added to the table, JClass LiveTable Pro controls the title's size and position. By default, titles are centered, and space is allocated for them before space is allocated the table.

Adding a Title

To add a title to a table, set the layout manager to JCTitleLayout, then add the title and the table to the panel. The following example creates a Label component as a table title:
     JCTitleLayout jct = new JCTitleLayout();
     setLayout(jct);
     Label label = new Label("Employee Listing");
     // Make the label stick out so we can see the offsets
     label.setBackground(Color.cyan);
     label.setForeground(Color.black);
     label.setFont(new Font("TimesRoman", Font.BOLD, 20));
     add("Top", label);

Positioning a Title

To set a title's position, use the setOffsets call. setOffsets takes an Inset as an argument. The Inset specifies the top, left, bottom and right offsets for the object. The following example adds a bottom title offset 0 pixels from the top, -15 pixels at left, 0 at bottom and +20 to the right:
     Label label2 = new Label("(0, -15, 0, 20)");
     // Make the label stick out so we can see the offsets
     label2.setBackground(Color.cyan);
     label2.setForeground(Color.black);
     add("Bottom", label2);
     jct.setOffsets("Bottom", new Insets(0, -15, 0, 20));

The following example adds another title, offset 20 pixels to the top, 0 pixels at left, -15 at bottom and 0 to the right:

     Label label3 = new Label("(20, 0, -15, 0)");
     // Make the label stick out so we can see the offsets
     label3.setBackground(Color.cyan);
     label3.setForeground(Color.black);
     add("Left", label3);
     jct.setOffsets("Left", new Insets(20, 0, -15, 0));
The next figure shows most of the valid title locations, derived from the previous code samples.

Title locations and offsets

These properties specify the space around the title. The previous figure shows how the offsets are measured when the title is on each side of the table. Offsets can be positive, negative, or JCTblEnum.NOVALUE.

Positive values add space between the title and the table. Negative values remove space between the title and the table. Setting an offset to zero causes the title to touch the cells/labels or the edge of the table component.

JCTblEnum.NOVALUE specifies a floating, unanchored offset; the actual positioning depends on the setting of the opposite offset property. For example, if LeftOffset and RightOffset are set to JCTblEnum.NOVALUE, JClass LiveTable Pro centers the title horizontally. If the opposite offset property is set to an explicit pixel value, the title is anchored at that value.

Resize Handling

During initial display, and any time the table is resized, JClass LiveTable Pro first calculates the space required to display the titles, using whatever is left for the cells and labels. If the table is made very small, unpredictable results may occur.


Row Height and Column Width

By default, JClass LiveTable Pro sets the height of rows to display one line of text. The width of columns is set by default to display 10 characters of text. If a cell value, image file, or component does not fit in its cell, the cell displays clipping arrows by default. Each row can have its own height, and each column its own width.

JClass LiveTable Pro provides two different ways to specify row height and column width: character and pixel. Character specification determines the height/width by the number of characters or lines that the row/column can display. Pixel specification determines the height/width by the explicit number of pixels.

Only one method can be used for a row or column. Pixel specification overrides character specification.

Note: When users interactively resize rows/columns, the row height/column width is specified by pixel regardless of how your application specified it. You can be notified and optionally change user resizing by using RESIZE_CELL.

Difference between Character and Pixel Row/Column specification

Character Height and Width

CharWidth specifies the number of characters a column can display. CharHeight specifies the number of lines of text a row can display. For these properties to control row height/column width, PixelWidth and PixelHeight must be set to JCTblEnum.NOVALUE.

Character specification of row height

Character specification is convenient when you know how many characters you want a row/column to display. It works best with non-proportional2 fonts because JClass LiveTable Pro uses the widest character along with the largest ascender/descender to guarantee that the specified number of characters will fit in the cell or label.

The following example sets the width of the third column to 15 characters:

	table.setCharWidth(2, 15);

To determine the pixel dimensions of a row or column whose height/width was set by CharWidth or CharHeight, use getPosition().

Pixel Height and Width

PixelWidth and PixelHeight specify column width and row height in pixels. You can set these properties to an explicit pixel value, JCTblEnum.NOVALUE, JCTblEnum.VARIABLE. (This value is discussed in detail in the following section).

Unless set to JCTblEnum.NOVALUE (default), these properties override the CharWidth and CharHeight properties. The next illustration shows setting PixelHeight to a pixel value.

Pixel specification of row height

The following code sets the width of the second column to 120 pixels:

     table.setPixelWidth(1, 120);
     // Wraps the text
     table.setMultiline(JCTblEnum.ALLCELLS, 1, true);

Variable Height and Width

An application can have JClass LiveTable Pro automatically size rows and columns to fit the contents of the table by setting PixelWidth and PixelHeight to JCTblEnum.VARIABLE. As your application changes table attributes affecting the cells' contents, JClass LiveTable Pro will resize the rows and columns to fit.3

When a cell contains a component, JClass LiveTable Pro sizes the cell to fit the component's preferred size.

Note: Once a user has resized a row or column, variable row/column resizing ends because the row/column size is specified by an explicit number of pixels. User cell editing does not automatically change the size of rows/columns.

If your application is making a lot of changes to a table, turn repainting off by setting Repaint to false, make the changes, and then turn repainting on to update the table display.

To determine the pixel dimensions of a row or column with variable height or width, use getPosition().

Hiding Rows and Columns

An application can "hide" rows and columns from the end-user by setting PixelHeight/PixelWidth to zero pixels.4 Though the row/column appears to have vanished, the application can set attributes or change cell values. The next figure illustrates the effect.

The current cell should not be in the hidden row/column.

Hiding the "Temperature" column

To reveal a hidden row/column, set the pixel height or width to a pixel value or JCTblEnum.NOVALUE (to use the character specification defined for the row/column).


Cell and Label Margins

You can alter the space between the cell borders and the contents of cells. MarginWidth sets the distance (in pixels) between the inside edge of the cell border and the top and bottom edge of the cell's contents (default: 5). MarginHeight specifies the margin (in pixels) between the inside edge of the cell border and the left/right edge of the cell's contents (default: 2). The next illustration shows the appearance of different margins. These properties affect all cells/labels in the table--margins cannot be set for individual cells.

Margin Height and Margin Width

The margin properties cannot be smaller than the value of FrameShadowThickness.


Foreground, Background and Shadow Colors

Specifying Colors

The background and foreground colors used for cells are specified by Background and Foreground. The following example displays the effect of setting the background color of column 2 to blue, and the foreground color for cell (1, 3) to white:
     table.setBackground(JCTblEnum.ALL, 1, Color.blue);
     table.setForeground(0, 3, Color.white);

Selected Cells

The background/foreground colors used for selected cells are specified by SelectedBackground and SelectedForeground. By default, selected cells are displayed in reverse video (i.e. the normal background and foreground color values have been swapped). The current cell displays the selection colors in its border.

When SelectedBackground is set to null, selected cells look identical to unselected cells--the background and foreground colors are the same as the colors defined for the cells.

Repeating Colors

JClass LiveTable Pro makes it easy to create rows or columns whose background and foreground colors alternate or cycle in a repeating pattern. To create a repeating pattern of background colors, set the RepeatBackgroundColors property as shown by the following example:
     Color[] c1 = { Color.orange, Color.green, Color.magenta };
     table.setRepeatBackgroundColors(c1);
     table.setBackground(JCTblEnum.ALLCELLS, JCTblEnum.ALLCELLS, JCTblEnum.REPEAT_COLUMN);
A list of repeating foreground colors can be created by setting the RepeatForegroundColors property.

You can define as many repeating colors as you like. The colors are always selected in the order listed.

JCTblEnum.REPEAT_ROW repeats colors in row order, whereas JCTblEnum.REPEAT_COLUMN repeats colors in column order. The following illustration displays the effect of each setting.

Repeating background colors

To set the foreground colors for the current context to a repeating color list defined by RepeatForegroundColors, set ForegroundContext to JCTblEnum.REPEAT_ROW or JCTblEnum.REPEAT_COLUMN.


Cell and Label Text Alignment

The horizontal and vertical alignment of text (or images) within cells and labels is specified by the Alignment property. Cell/label values can be centered or positioned along any side of the cell/label. Valid values for Alignment are: The following figure shows how the values of this property affect the text display.

Text alignment positions


Cell and Label Fonts

You can specify the font for the text in a cell or label with Font. JClass LiveTable Pro supports the use of one or more fonts in each cell/label. The example below sets a separate font for all column labels:
     table.setFont(JCTblEnum.LABEL, JCTblEnum.ALL, 
     new Font("TimesRoman", Font.ITALIC, 20));
JClass LiveTable Pro can use any of the fonts available to Java. See your Java documentation for details on finding and setting fonts.


Border Types and Sides

All cells and labels have a border around them. The visual look of the border, and the sides on which it appears, can be customized for individual cells and labels. The border width is specified for the entire table.

In addition, the table frame, which encloses the cells and labels, can have the visual look of its border customized.

Cell and Label Border Types

BorderType specifies the type of border drawn around cells or labels. The next illustration shows how each border type looks.

Border Types

The following example sets a blank border for a row:

     table.setBorderType(2, JCTblEnum.ALLCELLS, 
     JCTblEnum.BORDER_NONE);
Note: To see the effect of the ETCHED and FRAME borders, shadowThickness must be set to a value greater than 5 pixels.

Cell and Label Border Thickness

The width of the borders around the cells and labels is specified by ShadowThickness. This property applies to the entire table. By default, the borders are 1 pixel wide. The following image shows the visual effect of different border widths.

Setting Border Thickness

Cell and Label Border Sides

BorderSides specifies the sides of a cell or label that display the border type (specified by BorderType). By default, the border type is displayed on all sides of a cell/label. The following figure illustrates one of the visual effects that can be achieved.

Customized Cell Borders

The valid values for BorderSides are:

Specifying border sides is accomplished by OR-ing together all of the sides to have borders, for example:
	table.setBorderSides(JCTblEnum.ALL, 0, JCTblEnum.BORDERSIDE_LEFT | JCTblEnum.BORDERSIDE_TOP | JCTblEnum.BORDERSIDE_BOTTOM);

Frame Border Attributes

The FrameBorderType property enables you to specify the border type for the frame enclosing the cell and label areas. Its possible values are the same as those for BorderType, except that BORDER_FRAME_IN and BORDER_FRAME_OUT are not allowed. Its default value is BORDER_NONE.

The FrameShadowThickness property specifies the thickness of the frame shadows surrounding the cell and label areas. Its default value is 0 (no frame shadows).

A table with frame border attributes set

Shadow colors are calculated using the table's background color.


Images

JClass LiveTable Pro can display an image in each cell or label in the table. The image appears inside the margin of the cell.

Image Format

JClass LiveTable Pro supports the image file formats supported by the Java AWT: .gif and .jpeg. For more information on available file formats, see your Java documentation.

Specifying an Image

setCell(row, column, object) (where Object is an image) specifies the image to be displayed in the background of each cell or label. This property can take an image as its value.

The easiest way to specify an image stored in a file is to use the Java property converter to convert the filename string to the image data type that JCConverter() requires, as shown below:

     Image im = JCUtilConverter.toImage(this, "astronaut.gif");
     if (im != null) {
          JCString js = new JCString();
          js.add(im);
          table.setCell(3, 0, js);
}

Removing an Image

An image can be removed by using setCell(row, column, null).

Image Layout

The position of the image within the cell is specified in the same way as strings, using Alignment. The next figure shows how the values of this property change the positioning of the image.

Image layouts


Text and Image Clipping

When cell and label values don't fit in their cells, JClass LiveTable Pro can clip the display of the cell value. The DisplayClipArrow property determines which method is used. This sets whether or not to display clipping arrows when a cell/label value cannot be fully displayed in its cell/label (default: true). Clipping arrows appear at the bottom-right corner of a cell/label. The following figure shows the effect when DisplayClipArrows is set to true.

Cell value clipping and overflowing

Clipping

Clipped cell values display clipping arrows at the bottom-right corner of the cell by default. 5 This provides a visual indication that there is more text in the cell than currently displayed. To turn off the display of clipping arrows, set DisplayClipArrows to false.


Cell and Label Spanning

Spanning is a way to join a range of cells or labels together and treat them as one cell/label. A spanned range looks and acts like one cell/label that covers several rows and/or columns. There are many potential uses for spanning, including designing complex forms and displaying large images or components.

When you create a spanned range, the top-left cell in the range is extended over the entire range. The top-left cell is the source cell, and its value and attributes apply over the entire span, covering any values or attributes set for the other cells/labels in the range. Spanned ranges must begin at the top-left corner of the range. A span cannot contain both cells and labels. There must also be more than one cell/label in a spanned range; when a single-cell range is specified, it is removed from the list. The next figure shows an example of a table containing spanned ranges.

Spans is used to set a Vector of ranges of cells or labels. Each element of the Vector is an instance of a JCCellRange. A spanned range is a range of cells or labels that appear joined and can be treated as one cell. The top-left cell (specified by the start_row and start_column members) is the source cell for the spanned range. The cell/label value and attributes of the source cell are displayed in the spanned cell. Attributes for the spanned range must be set on the source cell.

Form design using spanned cells

Each item in a span list is an instance of a JCCellRange. A JCCellRange object defines the start and end columns/rows for the specified range.

The following example defines a cell that spans two columns:

     Vector spans = new Vector();
     JCCellRange r = new JCCellRange();
     r.reshape(0, 1, 0, 2);
     spans.addElement(r);
     table.setSpans(spans);


User Data

The UserData property allows an application to store any data for any context of cells or labels. JClass LiveTable Pro does not make any internal use of this property. This property is useful for attaching secondary data to a part of the table, such as the time the cell was last edited.


1 Rows/columns that are only partially visible are also included in the value of these properties.

2 All of the characters in a fixed-width font have the same width.

3 When width are height are set to zero, the row/column becomes hidden.

4 Users cannot interactively hide or reveal rows/columns.

5 The current cell never displays clipping arrows because it is an Text component.