All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.Grid

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----tea.set.Grid

public class Grid
extends Panel
implements ItemSelectable, Scrollable
Grid widget provides a flexible interface for managing grid layout. A cell in the grid can be any AWT components, and any components derived from the basic AWT components.

There are two ways of managing the space assignment. If absolute is set to false, which is the default, cells are resized to fit the display area. In this mode, the space assignment for rows and columns are automatic based on the preferred size of row and columns. The preferred size of a grid is the sum of preferred row heights and sum of preferred column widths. A preferred row height is the maximum preferred height of any components in a row, and similarly for preferred column width. The automatic space assignment can be overriden by calling setRowHeight() and setColWidth() methods.

Alternatively, a Grid can be set to absolute mode. In this mode cells are not resized to fit the screen. Instead, they are sized to their preferred row and column size. Notice since all cells on a row share same height and all cells on a column share same width, cells ARE resized to their preferred row height and preferred column width, as defined above. But no effort is made to fit all cells into the display area. This mode is primarily for scrolling.

The absolute mode can be specified for either horizontal, vertical, or both directions. To set both direction to absolute mode, call Grid.setAbsolute(Grid.VERTICAL | Grid.HORIZONTAL). If we want to fit the grid columns into the grid area, but let the grid rows having their preferred size, we can set one direction to absolute, Grid.setAbsolute(Grid.VERTICAL).

Users can resize rows or columns by dragging ruling lines separating rows and columns. If this happens, the layout mode of the Grid switches to absolute and row height/column width override mode automatically. This means no effort will be made by the Grid to layout cells to make everything fit into the display area from the point on. To disable user resizing, set resizable to false using setResizable().

To enable scrolling of Grid, simply attach a Scroller to the Grid widget. Since Grid implements the Scrollable interface, the scrolling will be by row and column instead of pixels. When a Scroller is attached to the Grid, the Grid is automatically switched to absolute mode. To attached a Scroller to a Grid, pass the Grid as the component managed by the Scroller, e.g. add(new Scroller(grid));

Rows and columns can be frozen. If a row is frozen, it will not be scrolled with other rows. If a column is frozen, it will not be scrolled with other column. Only rows and columns at the start of a grid can be frozen. If other rows/columns need to freezed, move them to the start of the grid first using moveRow() and moveCol(). To freeze n rows/columns at start of a grid, call Grid.setFrozenRow(n) or Grid.setFrozenCol(n).

Grid supports three cell selection mode, region, row, and column. Region selection is the most general. It can be enabled by calling Grid.setRegionSelectable() method. When region selection is enabled, an user can select a rectangular area of the grid by dragging the mouse over the area. An ItemEvent.SELECTED and ItemEvent.DESELECTED are generated for region selection and de-selection. To get the currently selected region, call Grid.getSelectedRegion().

Rows and columns can be selected by users if they are set to selectable. If multiSelect option is true, more than one row and column can be selected. Otherwise only one selection can exists at one time. Arrow keys can be used to move the row/column selections respectively if one is already selected. When a row or column is selected, an ItemEvent.SELECTED event is posted. When a row or column is deselected, a ItemEvent.DESELECTED event is posted.

Row/column can be set to selectable by calling Grid.setRowSelectable() and Grid.setColSelectable() methods. By default, if region is selectable, a mouse click starts a region selection. when row/column are selectable and region is not selectable, a mouse click inside any cell will select the row if row is selectable, or select the column if row is not selectable and column is selectable. Note however Grid does not track mouse events of its children, so if a cell holds an other component, the mouse event is not detected by the Grid and therefore would not cause any region/row/column selections.

Optionally, if row/column headers exist, a row or column can be selected by clicking on header cells. To force users to select row/column using row/column header, call Grid.setRowSelectable(true, true) or Grid.setColSelectable(true, true). In this case, if no header exists, an empty header is created to serve as row/column selectors. This mode also disables row/column selection from grid cells. The users are forced to select row/column from row/column headers only.

Note the row/column selector setting in Grid.setRowSelectable() and Grid.setColSelectable() only controls the creation of the row/column selectors. If row/column headers are set using Grid.setRowHeader() or Grid.setColHeader(), the headers are always able to be used for selecting row/column, regardless the flag values in the Grid.setRowSelectable() and Grid.setColSelectable().

A grid can be optionally drawn. There are two options available. VERTICAL option draws vertical lines between columns. HORIZONTAL option draws horizontal lines between rows. These options can be combined by bitwise OR them together. ALL flag is supplied to enable both grid lines. The width of border lines can be controlled by Grid.setLineWidth() method. The default width for lines is 2 pixels.

To change the ruling option, call Grid.setRuling(int) with one of the flags described above. This sets the grid wise ruling. The grid wise ruling option can be override for each cell by calling Grid.setRuling(int r, int c, int ruling). Per cell ruling option overrides the grid wise ruling. The ruling option of individual cells controls the grid line to the right of a cell and below a cell. For example, when the VERTICAL ruling flag is set for a cell, a vertical grid line is drawn at the right border of the cell. When the HORIZONTAL ruling flag is set for a cell, a horizontal grid line is drawn at the bottom border of the cell. If one or both are not set, the corresponding grid lines are not drawn for the particular cell.

The lines in a grid can be drawn in three different styles. The line style is controlled by the set3D() method. If PLAIN is specified, a single pixel line is drawn. If RAISED is specified, the line will be drawn in a 3D style raised above the grid surface. If LOWERED is specified, the line will be drawn in a 3D style embedded into the surface of the grid.

Row and column headers can be specified. If row headers are specified and row is selectable, then the row header is also the row selector. If row is selectable but there is not row header, then an empty row selector is added for each row. The same rule is used for column header and column selector. Row/column header is independent of row/column selectable setting. However, if row/column is selectable, the row/column header will always serve as row/column selector.

Row and column can be dynamically inserted or removed from the grid. When a row/column is inserted, the cells in the row/column are empty. User must call setCell() method to add components to the cells to make the row/column visible. Row and column can also be moved dynamically. When rows/columns are moved, all information about the row/column, such as select status, color, size, are carried with the moved row/column.

One or more rows and/or columns can be hiden. If a row or a column is hiden, it will not be displayed in the grid. However, the numbering of rows and columns will not change. For example, if row 2 is hiden, only rows 0, 1, 3, ... are displayed on screen. The original row 3 will remain row number 3 and will not be renumbered to row 2. The same is true for columns.

Spanning cells are supported. A spanning cell is a cell that takes more than one rows and/or columns. A spanning cell can be added to the grid using setCell(int, int, Component, int, int) method. When inserting or deleting row/column, the insertion or deletion point should not be at the middle of a spanning cell. Otherwise the screen layout will be not correct after the operation.

Color of individual cell can be set using Grid.setColor() method. When a cell's color is set using this method, the background color of the component inside the cell is changed to the color, in addition the cell will be filled with the cell color if cell component does not take all space inside the cell. The foreground of a cell can be changed through the Component interface of the cell component. If cell background color is not set using the methods mentioned above, the cell area is not painted if there is no component in the cell, and the areas leftover by a component inside a cell is not painted neither.

Gap spaces can be added to a cell component using Grid.setGap(). Spaces on four sides of the component can be specified. The gap spaces are added to the cell component's preferred size during space assignment calculation. Gap spaces are per cell attribute. There is not grid wide global gap attribute.

Cell components can be aligned in many different ways. The default cell alignment resize a cell component to fit the entire cell area. User can override this behavior by setting cell alignment explicitly. There are 15 possible alignments. Horizontally, you can choose from H_LEFT, H_CENTER, H_RIGHT. Vertically, you can choose from V_TOP, V_CENTER, and V_BOTTOM. The two can be bitwise or'ed to produce an alignment, or used by itself. If only one direction is specified, the other direction is to fit. For example, if alignment is set to V_TOP, the cell component is going to be aligned to the top of the cell area, and the width of the component is resized to the same width as the cell area.

For methods that take row/column number as parameter, the row/column number can be replaced with Grid.HEADER constant value. If Grid.HEADER is passed in as a row number, it specifies the column header row instead of the body row. If Grid.HEADER is passed in as a column number, it specifies the row header column instead of the body column. For example, to change the color of column header to red, call Grid.setColor(Grid.HEADER, Grid.ALL_CELL, Color.red). Only one of row and column parameter can have a value of HEADER. For methods

For methods that work on per cell bases, a special flag ALL_CELL is supplied to apply the operation to entire rows or columns. The grid.ALL_CELL can be used in place of a row or a column number in methods that expects both row and column number. When Grid.ALL_CELL is passed in as a row number, it means all rows. When Grid.ALL_CELL is passed in as a column number, it means all columns. If Grid.ALL_CELL is passed in for both row and column number, it means all cells in the grid. For example, to enable the horizontal ruling line for the header row, call grid.setRuling(Grid.HEADER, Grid.ALL_CELL, Grid.HORIZONTAL).

By default, any state changing method invocation will automatically cause a layout and repaint. This can be very expensive when a large number of invocation is expected. To optimize, AutoRepaint property is provided to control the layout/repaint activity. If AutoRepaint is set to false, no implicit repaint will be generated. User of the Grid has to explicitly invoke repaint after the sequence of method calls.

Known Bug:

On Solaris, there is no way to force a component to the front when one overlays another. Therefore the resize line may or may not be visible when resizing row/column (It may be hiden by other cell components).

Netscape 2.x has a bug causing components inside grid to change location undetectedly. This may cause strange behavior inside a grid. This bug is fixed in Netscape 3.0.

Grid supports four types of properties, cell, row, column, and grid level properties. Grid level properties are properties apply to the entire grid. They are accessed using the regular get...() and set...() methods. Cell properties apply to specific cells, they are accessed using get...(int row, int col, ...) and set...(int row, int col, ...) methods. The row and column properties apply to individual rows and columns. They are accessed using get...(int row, ...) and set...(int row, ...) methods. For property setting methods, the row and column numbers can be either normal row/column numbers, or the special number HEADER and ALL_CELL.

Grid supports the following grid level properties:
Property NameProperty TypeDescription
RowCountint Number of rows. Setting the number other than the current number of rows causes the grid to expend or shrink.
ColCountint Number of columns. Setting the number other than the current number of columns causes the grid to expend or shrink.
Absoluteint Absolute flag, NONE, VERTICAL, or HORIZONTAL.
Resizableboolean Allow user resizing of rows and columns.
InPlaceResizeboolean Resizing affects both rows/columns next to the resizing line.
Rulingint Grid wide ruling flag, NONE, VERTICAL, or HORIZONTAL.
3Dboolean Border line 3D style.
LineWidthint Border line width in pixels.
MultiSelectboolean Allow multiple rows or columns to be selected.
RowSelectableboolean Allow rows to be selected.
ColSelectableboolean Allow columns to be selected.
RegionSelectableboolean Allow grid region to be selected.
RowHeaderExistboolean (Readonly) True if row header column exists.
ColHeaderExistboolean (Readonly) True if column header row exists.
Alignmentint Grid level alignment flag.
SelectedRowint (Readonly) The index of the first selected row.
SelectedRowsint (Indexed, Readonly) Indexes of selected rows.
SelectedColint (Readonly) The index of the first selected column.
SelectedColsint (Indexed, Readonly) Indexes of selected columns.
SelectedObjectsObject(Indexed, Readonly) Row headers of selected rows.
SelectedRegionRegion (Readonly) Current selected region, or null if no region is selected.
RowRootint The topmost visible row.
ColRootint The leftmost visible column.
RowLastint (Readonly) Index of last visible row on screen.
ColLastint (Readonly) Index of the last visible column on screen.
FrozenRowint The number of rows frozen from the top.
FrozenColint The number of columns frozen from the left.
AutoRepaintboolean True if repaint requests are generated automatically whenever needed.

Grid supports the following cell level properties:
Property NameProperty TypeDescription
GapInsets Gap space around the child component.
Rulingint Per cell ruling flag, NONE, VERTICAL, or HORIZONTAL.
CellComponent Cell component.
SpanningDimension Spanning cell dimension.
Alignmentint Cell component alignment flagb.
ColorColor Cell background filling color.
Selectedboolean (Readonly) True if the cell is selected (as part of row, column, or region)
BoundsRectangle Bounds of the cell, excluding gap space and aligned.

Grid supports the following row level properties:
Property NameProperty TypeDescription
RowHeightint (Indexed) Preferred row height in pixels.
RowHeaderString (Indexed) Row header text string.
VisibleRowboolean (Readonly) True if the row is not hiden and is not scrolled off screen.
SelectedRowboolean True if the row is selected.

Grid supports the following column level properties:
Property NameProperty TypeDescription
ColWidthint (Indexed) Preferred column width in pixels.
ColHeaderString (Indexed) Column header text string.
VisibleColboolean (Readonly) True if the column is not hiden and is not scrolled off screen.
SelectedColboolean True if the column is selected.

Grid generates the following events:
Event TypeEvent IDGenerated Description
ItemEventItemEvent.SELECTED Row/Column/Region selection For row/column selection, ItemEvent.getItem() contains an Integer with the row/column number value. For region selection, ItemEvent.getItem() is a reference to a Grid.Region object of the selected region. When mouse drags during region selection, an ItemEvent is generated for every new row/column the mouse moves across. The ItemEvent.getStateChange() contains 0 for the ItemEvents generated by mouse drag, and contains 1 when the ItemEvent is generated when the mouse is released.
ItemEventItemEvent.DESELECTED Row/Column/Region deselection. ItemEvent.getItem() contains the deselected row/column number, or Grid.Region of the deselected region. ItemEvent.getStateChange() is 1.

See Also:
Scroller, TextGrid

Variable Index

 o ALL
Draw both horizontal and vertical ruling lines.
 o ALL_CELL
ALL_CELL can be used in place of a row or a column number in methods that expects both row and column number.
 o CENTER_BOTTOM
Center and bottom alignment.
 o CENTER_CENTER
Center and center alignment.
 o CENTER_TOP
Center and top alignment.
 o eventMgr
EventMgr object handles added event processing and dispatching.
 o FILL
Resize the component to fill the cell.
 o H_CENTER
Center at horizontal direction.
 o H_LEFT
Alignment flag determines how the cell components are aligned inside a cell.
 o H_RIGHT
Right align at horizontal direction.
 o HEADER
HEADER can be used as a parameter value where a row/column number is expected.
 o HORIZONTAL
This is used to specify horizontal ruling and horizontal absolute mode.
 o LEFT_BOTTOM
Left and bottom alignment.
 o LEFT_CENTER
Left and center alignment.
 o LEFT_TOP
Left and top alignment.
 o LOWERED
Draw lowered 3D lines.
 o NIL
NIL is used to serve as an argument to handleProperty to signal the absence of a particular parameter.
 o NONE
Don't draw any ruling.
 o PLAIN
Non-3D mode.
 o RAISED
Draw raised 3D lines.
 o RIGHT_BOTTOM
Right and bottom alignment.
 o RIGHT_CENTER
Right and center alignment.
 o RIGHT_TOP
Right and top alignment.
 o V_BOTTOM
Bottom align at vertical direction.
 o V_CENTER
Center at vertical direction.
 o V_TOP
Top align at vertical direction.
 o VERTICAL
This is used to specify vertical ruling and vertical absolute mode.

Constructor Index

 o Grid()
Construct an empty Grid.
 o Grid(int, int)
Construct a grid with row rows and col columns.

Method Index

 o addCol(int)
Add specified number of columns at the end of grid.
 o addItemListener(ItemListener)
Add an item listener.
 o addRow(int)
Add specified number of rows at the end of grid.
 o adjustRegion(Grid. Region, int, int, int, int)
Adjust a particular region.
 o adjustRegion(int, int, int, int)
Called when regions need to be adjusted, such as row/column move, insert, remove, etc..
 o alignCell(Rectangle, Dimension, int)
Align a rectangle area inside another rectangle area according to the alignment flag.
 o createCellInfo()
This method can be overriden by subclasses to provide a different CellInfo class.
 o createColInfo()
This method can be overriden by subclasses to provide a different ColInfo class.
 o createRowInfo()
This method can be overriden by subclasses to provide a different RowInfo class.
 o deselect()
Deselect all rows/columns/regions.
 o deselectCol(int)
Unselect a column.
 o deselectRegion()
Deselect a region.
 o deselectRow(int)
Unselect a row.
 o doLayout()
Layout the grid cells.
 o doRepaint(boolean, boolean)
This method should used by all derived class of Grid to send repaint request.
 o get3D()
Return the line 3D mode.
 o getAbsolute()
Return absolute flag, which is a bitwise OR of Grid.HORIZONTAL and Grid.VERTICAL.
 o getAlignment()
Return the current alignment.
 o getAlignment(int, int)
Return the per cell alignment.
 o getBottomCol()
Return the index of last visible column on screen.
 o getBottomRow()
Return the index of the last visible row on screen.
 o getBounds(int, int)
Get the cell location and cell size.
 o getCell(int, int)
Return the component at cell.
 o getCellInfo(int, int)
Get the per cell attributes.
 o getColCount()
Return the number of columns in the grid (excluding header column).
 o getColHeader()
Get the column header array.
 o getColHeader(int)
Get the column header for the specified column.
 o getColInfo(int)
Get the per column attributes.
 o getColor(int, int)
Return the per cell background color.
 o getColRoot()
Return the current col root.
 o getColWidth()
Get the current column width setting.
 o getFrozenCol()
Get the current number of frozen columns.
 o getFrozenRow()
Get the current number of frozen rows.
 o getGap(int, int)
Return the cell gap space.
 o getIncrement(int, int)
Get the increment for scrollbars.
 o getLineWidth()
Get the border line width.
 o getMaximum(int)
Return scrollbar maximum (columns).
 o getMinimum(int)
Return scrollbar minimum (columns).
 o getMinimumSize()
Return the minimum size of grid.
 o getPreferredColWidth(int)
Calculate the preferred column width.
 o getPreferredRowHeight(int)
Calculate the preferred row height.
 o getPreferredSize()
Return the preferred size of grid.
 o getPreferredSize(int, int)
Get the preferred size of the specified cell.
 o getRowCount()
Return the number of rows in the grid (excluding header row).
 o getRowHeader()
Get the row header array.
 o getRowHeader(int)
Get the row header for the specified row.
 o getRowHeight()
Get the current row heights setting.
 o getRowInfo(int)
Get the per row attributes.
 o getRowRoot()
Return the current row root.
 o getRuling()
Return the current ruling style.
 o getRuling(int, int)
Return the per cell ruling style.
 o getSelectedCol()
Return the selected column index.
 o getSelectedCols()
Return all selected column indexes.
 o getSelectedObjects()
Get the row headers of the selected rows.
 o getSelectedRegion()
Get the selected region.
 o getSelectedRow()
Return the selected row index.
 o getSelectedRows()
Return all selected row indexes.
 o getSpanning(int, int)
Return the spanning setting for the cell.
 o getValue(int)
Return the current value of the specified scrollbar.
 o getVisibleAmount(int)
Get the visible portion for the specified direction.
 o handleProperty(int, int, Object, Class, String)
This method is called by set property methods to handle ALL_CELL flag for row and column numbers.
 o hideCol(int)
Hide a column.
 o hideRow(int)
Hide a row.
 o highlight(int, int, boolean)
Highlight the specified cell.
 o insertCol(int, int)
Insert specified number of columns at the position specified.
 o insertRow(int, int)
Insert specified number of rows at the position specified.
 o isAutoRepaint()
Return true if auto repaint is on.
 o isColHeaderExist()
Return true if column header row exists.
 o isColSelectable()
Return true if column is selectable.
 o isInPlaceResize()
Get the InPlaceResize property.
 o isMultiSelect()
Return true if multiSelect is enabled.
 o isRegionSelectable()
Check the region selectable setting.
 o isResizable()
Return user resize flag.
 o isRowHeaderExist()
Return true if row header column exists.
 o isRowSelectable()
Return true if row is selectable.
 o isSelected(int, int)
Return true if the cell is selected as part of row, column, or region.
 o isSelectedCol(int)
Return true if specified column is selected.
 o isSelectedRow(int)
Return true if specified row is selected.
 o isSuspended()
Check if the paint is currently suspended.
 o isVisibleCol(int)
Return true if the specified column is visible.
 o isVisibleRow(int)
Return true if the specified row is currently visible.
 o locateCell(int, int)
Find the cell where the pointer is in.
 o moveCol(int, int)
Move a col from one position to a new position.
 o moveRow(int, int)
Move a row from one position to a new position.
 o paint(Graphics)
Paint the grid.
 o paintColHeader(Graphics, int)
Paint the specified column header cell if it's not empty.
 o paintRowHeader(Graphics, int)
Paint the specified row header cell if it's not empty.
 o paintText(Graphics, String, Rectangle, int)
Generate the pressed and unpressed image.
 o processEvent(AWTEvent)
Process and dispatch event.
 o processItemEvent(ItemEvent)
Process and dispatch item event.
 o processMouseEvent(MouseEvent)
Process mouse click events.
 o processMouseMotionEvent(MouseEvent)
Handle cell resize, row/column selection, tab keys and next focus, and arrow keys.
 o registerScroller(Scroller)
This function is called by Scroller at initialization time.
 o removeCol(int, int)
Remove specified number of columns at the position specified.
 o removeItemListener(ItemListener)
Remove an item listener.
 o removeRow(int, int)
Remove specified number of rows at the position specified.
 o repaint()
Explicit repaint cause the grid to be re-layed out.
 o selectCol(int)
Select a column.
 o selectCol(int, boolean)
Select of deselect a column.
 o selectRegion(Grid. Region)
Select the region specified in the region.
 o selectRow(int)
Select a row.
 o selectRow(int, boolean)
Select or deselect a row according to the select flag.
 o set3D(int)
Set the line 3D mode.
 o setAbsolute(int)
If absolute is set to true, cells will not be resized to fit the area.
 o setAlignment(int)
Set the alignment for the grid.
 o setAlignment(int, int, int)
Set the alignment for a particular cell.
 o setAutoRepaint(boolean)
If auto repaint mode is turned off (default to true), a repaint will not be generated by this Grid.
 o setCell(int, int, Component)
Set the component for a grid cell.
 o setCell(int, int, Component, int, int)
Set the component for a spanning cell.
 o setColCount(int)
Set the number of columns in this grid.
 o setColHeader(int, String)
Set one column header.
 o setColHeader(String[])
Set column headers.
 o setColor(int, int, Color)
Set the specified cell to the color.
 o setColRoot(int)
The col root is the column which will be displayed as the leftmost column.
 o setColSelectable(boolean)
Set column selectable to true or false.
 o setColSelectable(boolean, boolean)
Set column selectable to true or false.
 o setColWidth(int, int)
Set the specified column to the width.
 o setColWidth(int[])
Explicitly specify the column widths in the grid.
 o setFrozenCol(int)
Freeze the number of columns from the top column(0).
 o setFrozenRow(int)
Freeze the number of rows from the top row(0).
 o setGap(int, int, Insets)
Set a cell gap.
 o setInPlaceResize(boolean)
Is InPlaceResize property is true, user resize will resize the two rows/columns next to the resize line.
 o setLineWidth(int)
Set the border line width for 3D border lines.
 o setMultiSelect(boolean)
Set multiSelect mode to true or false.
 o setProperty(int, int, Object, Class, String)
This method calls the actual set property methods.
 o setRegionSelectable(boolean)
Enable or disable region selectability.
 o setResizable(boolean)
Enable/disable user resize through dragging ruling lines.
 o setRowCount(int)
Set the number of rows in this grid.
 o setRowHeader(int, String)
Set one row header.
 o setRowHeader(String[])
Set row headers.
 o setRowHeight(int, int)
Set the specified row to the height.
 o setRowHeight(int[])
Explicitly specify the row heights in the grid.
 o setRowRoot(int)
The row root is the row which will be displayed as the top row.
 o setRowSelectable(boolean)
Set row selectable to true or false.
 o setRowSelectable(boolean, boolean)
Set row selectable to true or false.
 o setRuling(int)
Set the ruling style.
 o setRuling(int, int, int)
Set the ruling for a particular cell.
 o setSpanning(int, int, Dimension)
Set the cell spanning dimension.
 o setSpanning(int, int, int, int)
Set the spanning cell size.
 o setSuspended(boolean)
Suspend layout and paint if the flag is true.
 o setValue(int, int)
Scroll the grid according to scrollbar value.
 o showCol(int)
Show a hiden column.
 o showCol(int, boolean)
Show or hide a column.
 o showRow(int)
Show a hiden row.
 o showRow(int, boolean)
Show or hide a row.
 o update(Graphics)
Override for double buffering.

Variables

 o HEADER
 public static final int HEADER
HEADER can be used as a parameter value where a row/column number is expected. This specifies the method would be applied to the header row/column instead of the body row/column. In methods that takes both row and column number, only one of the parameter can be HEADER because they are mutually exclusive.

 o ALL_CELL
 public static final int ALL_CELL
ALL_CELL can be used in place of a row or a column number in methods that expects both row and column number. If ALL_CELL is passed in as a row number, it means all rows. If ALL_CELL is passed in as a column number, it means all columns. If ALL_CELL is passed in for both row and column number, it means all cells in the grid.

 o NIL
 protected static final int NIL
NIL is used to serve as an argument to handleProperty to signal the absence of a particular parameter.

 o NONE
 public static final int NONE
Don't draw any ruling.

 o HORIZONTAL
 public static final int HORIZONTAL
This is used to specify horizontal ruling and horizontal absolute mode.

 o VERTICAL
 public static final int VERTICAL
This is used to specify vertical ruling and vertical absolute mode.

 o ALL
 public static final int ALL
Draw both horizontal and vertical ruling lines.

 o PLAIN
 public static final int PLAIN
Non-3D mode.

 o RAISED
 public static final int RAISED
Draw raised 3D lines.

 o LOWERED
 public static final int LOWERED
Draw lowered 3D lines.

 o H_LEFT
 public static final int H_LEFT
Alignment flag determines how the cell components are aligned inside a cell. The default is FILL. You can use either the final flags, e.g. LEFT_TOP, which is a product of OR of H_ and V_ flags. Or you can compose the flags using H_ and V_ flags explicitly. For example, if H_LEFT is passed as the alignment, the cell will be aligned to the left of the cell space, and the height of the cell component will be stretched to fit the cell height, and the cell component with will be the preferred width of the component if it's less than the cell space width. If LEFT_TOP is used, which is equivalent to H_LEFT|V_TOP, the cell component will be aligned to top left of cell space, and the component will not be stretched to fit neither dimension of the cell space.

 o H_CENTER
 public static final int H_CENTER
Center at horizontal direction.

 o H_RIGHT
 public static final int H_RIGHT
Right align at horizontal direction.

 o V_TOP
 public static final int V_TOP
Top align at vertical direction.

 o V_CENTER
 public static final int V_CENTER
Center at vertical direction.

 o V_BOTTOM
 public static final int V_BOTTOM
Bottom align at vertical direction.

 o FILL
 public static final int FILL
Resize the component to fill the cell.

 o LEFT_TOP
 public static final int LEFT_TOP
Left and top alignment.

 o LEFT_CENTER
 public static final int LEFT_CENTER
Left and center alignment.

 o LEFT_BOTTOM
 public static final int LEFT_BOTTOM
Left and bottom alignment.

 o CENTER_TOP
 public static final int CENTER_TOP
Center and top alignment.

 o CENTER_CENTER
 public static final int CENTER_CENTER
Center and center alignment.

 o CENTER_BOTTOM
 public static final int CENTER_BOTTOM
Center and bottom alignment.

 o RIGHT_TOP
 public static final int RIGHT_TOP
Right and top alignment.

 o RIGHT_CENTER
 public static final int RIGHT_CENTER
Right and center alignment.

 o RIGHT_BOTTOM
 public static final int RIGHT_BOTTOM
Right and bottom alignment.

 o eventMgr
 protected EventMgr eventMgr
EventMgr object handles added event processing and dispatching.

Constructors

 o Grid
 public Grid()
Construct an empty Grid.

 o Grid
 public Grid(int nrow,
             int ncol)
Construct a grid with row rows and col columns. The grid is empty after construction.

Parameters:
nrow - number of rows.
ncol - number of columns.

Methods

 o getRowCount
 public int getRowCount()
Return the number of rows in the grid (excluding header row).

Returns:
number of rows in grid.
 o setRowCount
 public void setRowCount(int nrow)
Set the number of rows in this grid. If the new number of rows is greater than the existing number of rows, additional empty rows are added to the grid. If the new number of rows is less than the existing number of rows, extra rows are removed from grid from the bottom.

Parameters:
nrow - number of rows.
 o getColCount
 public int getColCount()
Return the number of columns in the grid (excluding header column).

Returns:
number of columns in grid.
 o setColCount
 public void setColCount(int ncol)
Set the number of columns in this grid. If the new number of columns is greater than the existing number of columns, additional empty columns are added to the grid. If the new number of columns is less than the existing number of columns, extra columns are removed from grid from the right.

Parameters:
ncol - number of columns.
 o addRow
 public void addRow(int n)
Add specified number of rows at the end of grid. The newly added rows are empty initially. Consequently, the rows will not show up until components are added to the rows using setCell() method. Return the row number of the new row.

Parameters:
n - number of rows to add.
 o insertRow
 public synchronized void insertRow(int pos,
                                    int n)
Insert specified number of rows at the position specified. The newly inserted rows are empty initially. Consequently, the rows will not show up until components are added to the rows using setCell() method. Return the row number of the newly inserted rows.

Parameters:
pos - position to insert row.
n - number of rows to add.
 o removeRow
 public synchronized void removeRow(int pos,
                                    int n)
Remove specified number of rows at the position specified.

Parameters:
pos - row number.
n - number of rows to remove.
 o moveRow
 public synchronized void moveRow(int from,
                                  int to)
Move a row from one position to a new position. The spanning, alignment, and possible row height override information are carried along. Row selection and row hiding information are correctly maintained.

Parameters:
from - row number to move a row from.
to - row number to move a row to.
 o addCol
 public void addCol(int n)
Add specified number of columns at the end of grid. The newly added columns are empty initially. Consequently, the columns will not show up until components are added to the columns using setCell() method. Return the column number of the added column.

Parameters:
n - number of columns.
 o insertCol
 public synchronized void insertCol(int pos,
                                    int n)
Insert specified number of columns at the position specified. The newly inserted columns are empty initially. Consequently, the columns will not show up until components are added to the columns using setCell() method. Return the column number of the inserted columns.

Parameters:
pos - column number.
n - number of columns.
 o removeCol
 public synchronized void removeCol(int pos,
                                    int n)
Remove specified number of columns at the position specified.

Parameters:
pos - column number.
n - number of columns.
 o moveCol
 public synchronized void moveCol(int from,
                                  int to)
Move a col from one position to a new position. The spanning, alignment, and possible col width override information are carried along. Column selection and column hiding information are correctly maintained.

Parameters:
from - column number to move a column from.
to - column number to move a column to.
 o setGap
 public synchronized void setGap(int r,
                                 int c,
                                 Insets gap)
Set a cell gap. The Insets specifies the space around the cell component inside a cell.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
gap - cell component gap space.
 o getGap
 public Insets getGap(int r,
                      int c)
Return the cell gap space.

Returns:
cell gap space.
 o setAbsolute
 public synchronized void setAbsolute(int f)
If absolute is set to true, cells will not be resized to fit the area. If user supplied sizes exists, they are treated as absolute pixel size. Otherwise, preferred sizes are used to layout cells. No consideration is given if all cells fits into the area. This mode is automatically enabled when a Scroller is attached to a Grid.

Parameters:
f - a bitwise OR of Grid.HORIZONTAL or Grid.VERTICAL.
 o getAbsolute
 public int getAbsolute()
Return absolute flag, which is a bitwise OR of Grid.HORIZONTAL and Grid.VERTICAL.

Returns:
absolute mode.
 o setResizable
 public synchronized void setResizable(boolean ok)
Enable/disable user resize through dragging ruling lines. If Grid has been resized by user, it will be switched to absolute and row/column size override mode. Setting resizable to false with this function will NOT change the layout mode. In another word, the Grid will stay in absolute and size override mode even resizable is set to false. You need to call setAbsolute(Grid.NONE) and setRowHeight(null) and setColWidth(null) explicitly to restore to default layout mode.

Parameters:
ok - true to enable user resize, false to enable.
 o isResizable
 public boolean isResizable()
Return user resize flag.

Returns:
resizable flag.
See Also:
setResizable
 o setInPlaceResize
 public synchronized void setInPlaceResize(boolean f)
Is InPlaceResize property is true, user resize will resize the two rows/columns next to the resize line. The overall size of the rows/columns will not be changed.

Parameters:
f - inplace resize flag.
 o isInPlaceResize
 public boolean isInPlaceResize()
Get the InPlaceResize property.

Returns:
true if inplace resize mode is on.
 o setRowHeight
 public synchronized void setRowHeight(int r,
                                       int h)
Set the specified row to the height. If absolute is true, this size is the actual pixel size for each row. Otherwise, it specifies the preferred height of this row, but the actual height of the rows is dependent on the display area size.

Parameters:
r - row number. All rows if it equals to Grid.ALL_CELL.
h - row height.
 o setRowHeight
 public synchronized void setRowHeight(int rheight[])
Explicitly specify the row heights in the grid. If absolute mode is true, the values in the array is the actual pixel size of each row. Otherwise, the values in the array is treated as the preferred size of the rows. The row height specification includes the header row. If the argument array has less elements than the number of rows, the remaining row heights will not be changed. Passing a null pointer will cancel row height override mode.

Parameters:
rheight - row heights array.
 o getRowHeight
 public int[] getRowHeight()
Get the current row heights setting. The meaning of row heights depends on the absolute setting. For details, see setRowHeight().

Returns:
row heights.
 o setColWidth
 public synchronized void setColWidth(int c,
                                      int w)
Set the specified column to the width. If absolute is true, this size is the actual pixel size for each column. Otherwise, it specifies the preferred width of this column, but the actual width of the col is dependent on the display area size.

Parameters:
c - column number. All columns if it equals Grid.ALL_CELL.
w - column width.
 o setColWidth
 public synchronized void setColWidth(int cwidth[])
Explicitly specify the column widths in the grid. If absolute mode is true, the values in the array is the actual pixel size of each column. Otherwise, the values in the array is treated as the preferred size of the columns. The column width specification includes the header column. If the argument array has less elements than the number of columns, the remaining column widths will not be changed. Passing a null pointer will cancel column width override mode.

Parameters:
cwidth - column widths array.
 o getColWidth
 public int[] getColWidth()
Get the current column width setting. The meaning of column widths depends on the absolute setting. For details, see setColWidth().

Returns:
column widths.
 o setRuling
 public synchronized void setRuling(int ruling)
Set the ruling style. The argument can be a product of bitwise OR of the available flags. For example, HORIZONTAL|VERTICAL will cause both horizontal and vertical ruling to be drawn. This method sets the grid wide ruling style. It can be overriden by per cell ruling style.

Parameters:
ruling - ruling flag.
 o setRuling
 public synchronized void setRuling(int r,
                                    int c,
                                    int ruling)
Set the ruling for a particular cell. The argument can be a product of bitwise OR of the available flags. The per cell ruling flag controls the drawing of the ruling lines below and to the right of the specified cell. For example, HORIZONTAL|VERTICAL will cause both horizontal and vertical ruling to be drawn below and at right side of the specified cell. The per cell ruling flag overrides the grid wise ruling flag.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
ruling - ruling flag.
 o getRuling
 public int getRuling()
Return the current ruling style. Use bitwise AND to check if a flag is set.

Returns:
ruling flag.
 o getRuling
 public int getRuling(int r,
                      int c)
Return the per cell ruling style. Use bitwise AND to check if a flag is set. If the specified cell is part of a spanning cell, the spanning cell ruling option is returned.

Parameters:
r - row number.
c - column number.
Returns:
cell ruling flag.
 o set3D
 public synchronized void set3D(int mode)
Set the line 3D mode. The value can be one of: PLAIN, RAISED, and LOWERED. The mode defaults to RAISED.

Parameters:
mode - 3D mode.
 o get3D
 public int get3D()
Return the line 3D mode.

Returns:
3D mode.
 o setLineWidth
 public synchronized void setLineWidth(int w)
Set the border line width for 3D border lines. This does not affect non-3D lines.

Parameters:
w - line width in pixels.
 o getLineWidth
 public int getLineWidth()
Get the border line width.

 o setMultiSelect
 public synchronized void setMultiSelect(boolean s)
Set multiSelect mode to true or false. If multiSelect is enabled, more than one row and/or column can be selected. Otherwise, only one row or column can be selected at any given time. MultiSelect defaults to false.

Parameters:
true - for multiple select mode.
 o isMultiSelect
 public boolean isMultiSelect()
Return true if multiSelect is enabled.

Returns:
multi-select mode.
 o setRowSelectable
 public synchronized void setRowSelectable(boolean s)
Set row selectable to true or false. If row is selectable, a mouse click inside a cell selects the row where the cell is in (Note: Some components do not pass mouse events up. In this case a mouse click inside those cells will not select a row). If row headers exist, the row header will serve as the row selector. RowSelectable defaults to false.

Parameters:
s - true to make row selectable.
 o setRowSelectable
 public synchronized void setRowSelectable(boolean s,
                                           boolean sel)
Set row selectable to true or false. If row is selectable, a row selector will be added to each row if useRowHeader is true. If row headers exist, the row header will serve as the row selector. RowSelectable and useRowHeader defaults to false. If row is selectable and no row selector exists, row can be selected by clicking in any cell inside a row.

Parameters:
s - true to make row selectable.
sel - create row selector if true.
 o setColSelectable
 public synchronized void setColSelectable(boolean s)
Set column selectable to true or false. If column is selectable, a mouse click inside a cell selects the column where the cell is in (Note: Some components do not pass mouse events up. In this case a mouse click inside those cells will not select a column). If column headers exist, the column header will serve as the column selector. ColSelectable defaults to false.

Parameters:
s - true to make column selectable.
 o setColSelectable
 public synchronized void setColSelectable(boolean s,
                                           boolean sel)
Set column selectable to true or false. If column is selectable, a column selector will be added to each column if useColHeader is true. If column headers exist, the column header will serve as the column selector. ColSelectable and useColHeader defaults to true. If column is selectable and no column selector exists, column can be selected by clicking in any cell inside a column.

Parameters:
s - true to make column selectable.
sel - true to create column selector.
 o isRowSelectable
 public boolean isRowSelectable()
Return true if row is selectable.

Returns:
true if row is selectable.
 o isColSelectable
 public boolean isColSelectable()
Return true if column is selectable.

Returns:
true if column is selectable.
 o setRegionSelectable
 public synchronized void setRegionSelectable(boolean f)
Enable or disable region selectability.

Parameters:
f - true to enable and false to disable.
 o isRegionSelectable
 public boolean isRegionSelectable()
Check the region selectable setting.

Returns:
true if region is selected.
 o setRowHeader
 public synchronized void setRowHeader(int r,
                                       String header)
Set one row header. If row is selectable, the row header also serves as the row selector. Newline '\n' can be embedded inside the header. Text separated by newline are drawn as separate lines.

Parameters:
r - row number.
header - row header string.
 o setRowHeader
 public synchronized void setRowHeader(String header[])
Set row headers. If row is selectable, the row header also serves as the row selector. Newline '\n' can be embedded inside the header. Text separated by newline are drawn as separate lines.

Parameters:
header - row header string array.
 o getRowHeader
 public synchronized String[] getRowHeader()
Get the row header array. If no row header is set, it returns an array of all nulls. Otherwise the header cell labels are returned in an array.

Returns:
row header strings.
 o getRowHeader
 public synchronized String getRowHeader(int r)
Get the row header for the specified row. If the row header is not set, it returns a null.

Parameters:
r - row number.
Returns:
row header for the row.
 o isRowHeaderExist
 public boolean isRowHeaderExist()
Return true if row header column exists.

Returns:
true if row header exists.
 o setColHeader
 public synchronized void setColHeader(int c,
                                       String header)
Set one column header. If column is selectable, the column header also serves as the column selector. Newline '\n' can be embedded inside the header. Text separated by newline are drawn as separate lines.

Parameters:
c - column number.
header - column header string.
 o setColHeader
 public synchronized void setColHeader(String header[])
Set column headers. If column is selectable, the column header also serves as the column selector. Newline '\n' can be embedded inside the header. Text separated by newline are drawn as separate lines.

Parameters:
header - column header string array.
 o getColHeader
 public synchronized String[] getColHeader()
Get the column header array. If no column header is set, it returns an array of all nulls. Otherwise the header cell labels are returned in an array.

Returns:
column header strings.
 o getColHeader
 public String getColHeader(int c)
Get the column header for the specified column. If the column header is not set, returns null.

Parameters:
c - column number.
Returns:
column header for the column.
 o isColHeaderExist
 public boolean isColHeaderExist()
Return true if column header row exists.

Returns:
true if column header exists.
 o setCell
 public synchronized void setCell(int r,
                                  int c,
                                  Component cell)
Set the component for a grid cell. If a component is already attached to the cell, it will be removed from the grid and replaced with the new component. If the cell is inside the spanning area of another cell, the spanning will be removed. If the component passed into setCell() is null, the current cell component is removed from the grid, and the cell becomes empty. The Grid.ALL_CELL can be used as the row or column number to set multiple cells components. But since a component can only be at one place, the only reasonable component for multiple cells is the null component. In another word, Grid.ALL_CELL can be used to clear multiple cell components, but would not work for setting multiple cell components.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
cell - cell component.
 o setCell
 public synchronized void setCell(int r,
                                  int c,
                                  Component cell,
                                  int spanRow,
                                  int spanCol)
Set the component for a spanning cell. If a component is already attached to the cell, it will be removed from the grid and replaced with the new component. The spanning cell occupies number of rows and columns specified by spanRow and spanCol. The spanRow and spanCol parameters must both be greater than zero.

Parameters:
r - row number.
c - column number.
cell - cell component.
spanRow - number of rows for spanning cell.
spanCol - number of columns for spanning cell.
 o getCell
 public Component getCell(int r,
                          int c)
Return the component at cell. If not component is attached to the cell, a null will be returned.

Parameters:
r - row number.
c - column number.
Returns:
cell component.
 o setSpanning
 public synchronized void setSpanning(int r,
                                      int c,
                                      int spanRow,
                                      int spanCol)
Set the spanning cell size. The spanRow and spanCol must be greater than zero.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
spanRow - number of rows for spanning cell.
spanCol - number of columns for spanning cell.
 o setSpanning
 public synchronized void setSpanning(int r,
                                      int c,
                                      Dimension span)
Set the cell spanning dimension.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
span - spanning dimension, Dimension.width is the number of columns, and Dimension.height is the number of rows.
 o getSpanning
 public Dimension getSpanning(int r,
                              int c)
Return the spanning setting for the cell. If the specified cell is not a spanning cell, it returns null. Otherwise it returns a Dimension object with Dimension.width equals to the number of columns and Dimension.height equals to the number of rows of the spanning cell.

Parameters:
r - row number.
c - column number.
Returns:
spanning cell dimension.
 o setAlignment
 public synchronized void setAlignment(int alignment)
Set the alignment for the grid. This method sets the grid wide alignment flag. It's overriden by per cell alignment flag if per cell alignment flag is set.

Parameters:
alignment - cell alignment flag.
 o setAlignment
 public synchronized void setAlignment(int r,
                                       int c,
                                       int alignment)
Set the alignment for a particular cell. This overrides the grid wise alignment flag.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
alignment - cell alignment flag.
 o getAlignment
 public int getAlignment()
Return the current alignment.

Returns:
grid wise alignment.
 o getAlignment
 public int getAlignment(int r,
                         int c)
Return the per cell alignment.

Parameters:
r - row number.
c - column number.
Returns:
cell alignment.
 o setColor
 public synchronized void setColor(int r,
                                   int c,
                                   Color color)
Set the specified cell to the color. It clears the explicit color if color parameter is null, in which case the cell component's own color is used. The different between setting color using Grid.setColor(), and setting color through the Component interface of cell component is: 1. If there are colors in a cell, the color in the color area will not be affected if color is set through Component interface of component cell. 2. If a cell is empty, the color can only be set using Grid.setColor().

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
c - column number. All columns if it equals Grid.ALL_CELL.
color - cell color. Clear explicit color if null.
 o getColor
 public Color getColor(int r,
                       int c)
Return the per cell background color.

Parameters:
r - row number.
c - column number.
Returns:
cell background color.
 o hideRow
 public void hideRow(int r)
Hide a row.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
 o showRow
 public void showRow(int r)
Show a hiden row.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
 o showRow
 public synchronized void showRow(int r,
                                  boolean showit)
Show or hide a row.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
showit - true to show a hiden row, false to hide a row.
 o isVisibleRow
 public boolean isVisibleRow(int r)
Return true if the specified row is currently visible. Rows above row root and below frozen rows are counted as hiden.

Parameters:
r - row number.
Returns:
true if row is visible.
 o hideCol
 public void hideCol(int c)
Hide a column.

Parameters:
c - column number. All columns if it equals Grid.ALL_CELL.
 o showCol
 public void showCol(int c)
Show a hiden column.

Parameters:
c - column number. All columns if it equals Grid.ALL_CELL.
 o showCol
 public synchronized void showCol(int c,
                                  boolean showit)
Show or hide a column.

Parameters:
c - column number. All columns if it equals Grid.ALL_CELL.
showit - true to show a hiden column, false to hide a column.
 o isVisibleCol
 public boolean isVisibleCol(int c)
Return true if the specified column is visible. Columns left of column root and right of frozen columns are counted as hiden.

Parameters:
c - column number.
Returns:
true if column is visible.
 o deselectRow
 public void deselectRow(int r)
Unselect a row. A LIST_DESELECT event is generated when a row is deselected.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
 o deselectCol
 public void deselectCol(int c)
Unselect a column. A LIST_DESELECT event is generated when a column is deselected.

Parameters:
c - column number. All columns if it equals Grid.ALL_CELL.
 o selectRow
 public void selectRow(int r)
Select a row. If multiSelect is not enabled, this will cause other selections to be cleared. A LIST_SELECT event is generated when a row is selected.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
 o selectRow
 public synchronized void selectRow(int r,
                                    boolean sel)
Select or deselect a row according to the select flag.

Parameters:
r - row number. All rows if it equals Grid.ALL_CELL.
sel - select flag. True to select a row.
 o selectCol
 public void selectCol(int c)
Select a column. If multiSelect is not enabled, this will cause other selections to be cleared. A LIST_SELECT event is generated when a row is selected.

Parameters:
c - column number.
 o selectCol
 public synchronized void selectCol(int c,
                                    boolean sel)
Select of deselect a column.

Parameters:
c - column number. All columns if it equals to Grid.ALL_CELL.
sel - select or deselect the column.
 o getSelectedRow
 public synchronized int getSelectedRow()
Return the selected row index. If more than one row is selected, the first selected row is returned.

Returns:
row number of selected row. -1 if no row is selected.
 o getSelectedRows
 public synchronized int[] getSelectedRows()
Return all selected row indexes.

Returns:
row numbers of selected rows.
 o getSelectedCol
 public synchronized int getSelectedCol()
Return the selected column index. If more than one column is selected, the first selected column is returned.

Returns:
column number of selected column. -1 if no column is selected.
 o getSelectedCols
 public synchronized int[] getSelectedCols()
Return all selected column indexes.

Returns:
column numbers of selected columns.
 o getSelectedObjects
 public Object[] getSelectedObjects()
Get the row headers of the selected rows.

Returns:
row headers of the selected rows.
 o isSelectedRow
 public boolean isSelectedRow(int r)
Return true if specified row is selected.

Parameters:
r - row number.
Returns:
true if row is selected.
 o isSelectedCol
 public boolean isSelectedCol(int c)
Return true if specified column is selected.

Parameters:
c - column number.
Returns:
true if column is selected.
 o deselect
 public synchronized void deselect()
Deselect all rows/columns/regions. This is more efficient than calling deselectRow(Grid.ALL_CELL) or deselectCol(Grid.ALL_CELL).

 o selectRegion
 public synchronized void selectRegion(Grid. Region reg)
Select the region specified in the region. Generates an ItemEvent SELECTED event.

Parameters:
reg - grid region.
 o deselectRegion
 public synchronized void deselectRegion()
Deselect a region. Generates an ItemEvent DESELECTED event.

 o getSelectedRegion
 public Grid. Region getSelectedRegion()
Get the selected region. If no region is selected, return null.

Returns:
selected region or null if not region is selected.
 o isSelected
 public boolean isSelected(int r,
                           int c)
Return true if the cell is selected as part of row, column, or region.

Returns:
true if the cell is selected.
 o setRowRoot
 public synchronized void setRowRoot(int row)
The row root is the row which will be displayed as the top row. Rows above the row root is not displayed. Frozen rows override row root. This is used mostly for scrolling.

Parameters:
row - row number.
 o setColRoot
 public synchronized void setColRoot(int col)
The col root is the column which will be displayed as the leftmost column. Columns left of the column root is not displayed. Frozen columns override column root. This is used mostly for scrolling.

Parameters:
col - column number.
 o getRowRoot
 public int getRowRoot()
Return the current row root. See setRowRoot() for an explanation of row root.

Returns:
the root row number.
 o getBottomRow
 public int getBottomRow()
Return the index of the last visible row on screen.

Returns:
index of last visible row.
 o getColRoot
 public int getColRoot()
Return the current col root. See setColRoot() for an explanation of col root.

Returns:
the root column number.
 o getBottomCol
 public int getBottomCol()
Return the index of last visible column on screen.

Returns:
the index of last visible column.
 o setFrozenRow
 public synchronized void setFrozenRow(int nrow)
Freeze the number of rows from the top row(0). Rows freezing are not affected by the row root setting. Set freeze row to zero(0) to unfreeze all rows.

Parameters:
nrow - number of rows.
 o setFrozenCol
 public synchronized void setFrozenCol(int ncol)
Freeze the number of columns from the top column(0). Columns freezing are not affected by the column root setting. Set freeze column to zero(0) to unfreeze all columns.

Parameters:
ncol - number of columns.
 o getFrozenRow
 public int getFrozenRow()
Get the current number of frozen rows.

Returns:
number of frozen rows.
 o getFrozenCol
 public int getFrozenCol()
Get the current number of frozen columns.

Returns:
number of frozen columns.
 o setAutoRepaint
 public void setAutoRepaint(boolean f)
If auto repaint mode is turned off (default to true), a repaint will not be generated by this Grid. The user of the Grid is responsible for explicitly calling repaint() method on the Grid.

Parameters:
f - auto repaint flag.
 o isAutoRepaint
 public boolean isAutoRepaint()
Return true if auto repaint is on.

Returns:
auto repaint mode.
 o getPreferredSize
 public Dimension getPreferredSize()
Return the preferred size of grid. The preferred size is the sum of preferred row heights and sum of preferred column width. The preferred row height is defined as the maximum preferred height of cells in one row. Similarly for preferred column width. If coordinates are explicitly supplied, the preferred size is simply calculated using the coordinates.

Returns:
preferred size.
Overrides:
getPreferredSize in class Container
 o getMinimumSize
 public Dimension getMinimumSize()
Return the minimum size of grid. It's currently same as preferred size.

Returns:
minimum size.
Overrides:
getMinimumSize in class Container
 o doLayout
 public void doLayout()
Layout the grid cells. Called automatically.

Overrides:
doLayout in class Container
 o paint
 public void paint(Graphics g)
Paint the grid.

Parameters:
g - Graphics context of this component.
Overrides:
paint in class Container
 o update
 public void update(Graphics g)
Override for double buffering.

Parameters:
g - Graphics context of this component.
Overrides:
update in class Component
 o repaint
 public void repaint()
Explicit repaint cause the grid to be re-layed out.

Overrides:
repaint in class Component
 o addItemListener
 public void addItemListener(ItemListener listener)
Add an item listener.

Parameters:
listener - item listener.
 o removeItemListener
 public void removeItemListener(ItemListener listener)
Remove an item listener.

Parameters:
listener - item listener.
 o processEvent
 public void processEvent(AWTEvent e)
Process and dispatch event.

Parameters:
e - event object.
Overrides:
processEvent in class Container
 o processItemEvent
 public void processItemEvent(ItemEvent e)
Process and dispatch item event.

Parameters:
e - item event.
 o processMouseMotionEvent
 public synchronized void processMouseMotionEvent(MouseEvent e)
Handle cell resize, row/column selection, tab keys and next focus, and arrow keys.

Parameters:
e - event object.
Overrides:
processMouseMotionEvent in class Component
 o processMouseEvent
 public void processMouseEvent(MouseEvent e)
Process mouse click events. This handles row/column resize, row and column selection, and region selection.

Overrides:
processMouseEvent in class Component
 o registerScroller
 public synchronized void registerScroller(Scroller scr)
This function is called by Scroller at initialization time. The Grid will call Scroller.notifyUpdate() when scrollbar values need to be recalculated.

Parameters:
scr - Scroller where this grid is attached to.
 o getMinimum
 public int getMinimum(int orientation)
Return scrollbar minimum (columns).

Parameters:
orientation - VERTICAL or HORIZONTAL.
Returns:
minimum scrollbar value for the orientation.
 o getMaximum
 public synchronized int getMaximum(int orientation)
Return scrollbar maximum (columns).

Parameters:
orientation - VERTICAL or HORIZONTAL.
Returns:
maximum scrollbar value for the orientation.
 o getValue
 public int getValue(int orientation)
Return the current value of the specified scrollbar.

Parameters:
orientation - VERTICAL or HORIZONTAL.
Returns:
scrollbar value for the orientation.
 o getVisibleAmount
 public int getVisibleAmount(int orientation)
Get the visible portion for the specified direction. This is only an approximate.

Parameters:
orientation - VERTICAL or HORIZONTAL.
Returns:
scrollbar visible value for the orientation.
 o getIncrement
 public synchronized int getIncrement(int orientation,
                                      int direction)
Get the increment for scrollbars.

Parameters:
orientation - VERTICAL or HORIZONTAL.
direction - UNIT_DECREMENT, UNIT_INCREMENT, BLOCK_DECREMENT, or BLOCK_INCREMENT.
Returns:
scrollbar increments for the orientation.
 o setValue
 public void setValue(int orientation,
                      int v)
Scroll the grid according to scrollbar value.

Parameters:
orientation - VERTICAL or HORIZONTAL.
v - scrollbar value for the orientation.
 o getBounds
 public Rectangle getBounds(int r,
                            int c)
Get the cell location and cell size. The location of the cell is relative to this grid. The size is adjusted for border lines and cell gaps.

Parameters:
r - row number.
c - column number.
Returns:
cell location and size.
 o locateCell
 public Point locateCell(int x,
                         int y)
Find the cell where the pointer is in. The calculation is based on coordinates and spanning cell information. If the cell is in a column header or a row header, the row number or the column number would be set to Grid.HEADER. If the point does not fall into any cell area, a null is returned.

Parameters:
x - x coordinate. Relative to grid.
y - y coordinate. Relative to grid.
Returns:
column and row number. Point.x is the column number. Point.y is the row number.
 o highlight
 public synchronized void highlight(int r,
                                    int c,
                                    boolean hl)
Highlight the specified cell. Highlight the same row twice return the color to its original state.

Parameters:
r - row number.
 o getCellInfo
 protected Grid. CellInfo getCellInfo(int r,
                                      int c)
Get the per cell attributes. The attributes are maintained by Grid and the derived classes only need to make sure to case the object returned by this method to the correct class type.

Parameters:
r - row number.
c - column number.
Returns:
cell attributes.
 o createCellInfo
 protected Grid. CellInfo createCellInfo()
This method can be overriden by subclasses to provide a different CellInfo class.

Returns:
a new CellInfo object.
 o getRowInfo
 protected Grid. RowInfo getRowInfo(int r)
Get the per row attributes. The attributes are maintained by Grid and the derived classes only need to make sure to case the object returned by this method to the correct class type.

Parameters:
r - row number.
Returns:
row attributes.
 o createRowInfo
 protected Grid. RowInfo createRowInfo()
This method can be overriden by subclasses to provide a different RowInfo class.

Returns:
a new RowInfo object.
 o getColInfo
 protected Grid. ColInfo getColInfo(int r)
Get the per column attributes. The attributes are maintained by Grid and the derived classes only need to make sure to case the object returned by this method to the correct class type.

Parameters:
r - column number.
Returns:
column attributes.
 o createColInfo
 protected Grid. ColInfo createColInfo()
This method can be overriden by subclasses to provide a different ColInfo class.

Returns:
a new ColInfo object.
 o getPreferredSize
 protected Dimension getPreferredSize(int r,
                                      int c)
Get the preferred size of the specified cell. The default is the preferred size of the component in the cell. It can be override by derived class to provide a different semantics.

Parameters:
r - row number.
c - column number.
Returns:
the preferred size of the specified cell.
 o handleProperty
 protected synchronized boolean handleProperty(int n1,
                                               int n2,
                                               Object val,
                                               Class type,
                                               String prop)
This method is called by set property methods to handle ALL_CELL flag for row and column numbers. It in turn calls setProperty() to set the property. If row and/or column number are ALL_CELL, this method provides the loop to call setProperty for all the specified cells, and it returns true. If none of the row and column number is ALL_CELL, it simply returns false. This method is normally not overriden, but can be used by derived class to handle ALL_CELL for properties.

Parameters:
n1 - index one.
n2 - index two.
val - property value.
prop - method name.
Returns:
true if property has been properly set.
 o setProperty
 protected void setProperty(int n1,
                            int n2,
                            Object val,
                            Class type,
                            String prop)
This method calls the actual set property methods. It decides which method to call based on the property name. Derived class can override this method to check for additional properties. If this method is derived, it's important it's chained back to the super class method.

For methods that only take on index, the first index will be used unless its value is NIL, in which case the second index will be used.

Parameters:
n1 - index one.
n2 - index two.
val - property value.
prop - property name.
 o doRepaint
 protected void doRepaint(boolean dolayout,
                          boolean calcsize)
This method should used by all derived class of Grid to send repaint request. It honors the AutoRepaint property.

 o setSuspended
 protected synchronized void setSuspended(boolean t)
Suspend layout and paint if the flag is true. This is for advance uses where a large amount of activities are performed, in which case frequent layout and paint will degrade the performance. When suspension is lefted, a repaint is issued automatically to bring everything in sync.

Parameters:
t - true to suspend layout and repaint.
 o isSuspended
 protected boolean isSuspended()
Check if the paint is currently suspended.

Returns:
true if paint is suspended.
 o alignCell
 protected Rectangle alignCell(Rectangle box,
                               Dimension psize,
                               int align)
Align a rectangle area inside another rectangle area according to the alignment flag.

Parameters:
box - outer rectangle area.
psize - inner rectangle area.
align - alignment flag.
Returns:
aligned rectangle area position and size.
 o adjustRegion
 protected synchronized void adjustRegion(int r,
                                          int c,
                                          int nrow,
                                          int ncol)
Called when regions need to be adjusted, such as row/column move, insert, remove, etc..

Parameters:
r - row number.
c - column number.
nrow - the row adjustment.
ncol - the column adjustment.
 o adjustRegion
 protected synchronized void adjustRegion(Grid. Region reg,
                                          int r,
                                          int c,
                                          int nrow,
                                          int ncol)
Adjust a particular region.

Parameters:
r - row number.
c - column number.
nrow - the row adjustment.
ncol - the column adjustment.
 o getPreferredRowHeight
 protected int getPreferredRowHeight(int r)
Calculate the preferred row height. The preferred row height of a row is the maximum preferred height of all cells on the row.

Parameters:
r - row number.
Returns:
the preferred row height.
 o getPreferredColWidth
 protected int getPreferredColWidth(int c)
Calculate the preferred column width. The preferred column width of a column is the maximum preferred width of all cells on the column.

Parameters:
r - column number.
Returns:
the preferred column width.
 o paintText
 protected void paintText(Graphics g,
                          String str,
                          Rectangle bound,
                          int align)
Generate the pressed and unpressed image. The graphics object parameter is clipped to the area of this cell.

Parameters:
g - graphics object.
str - text string.
text - alignment flag.
 o paintRowHeader
 protected void paintRowHeader(Graphics g,
                               int r)
Paint the specified row header cell if it's not empty.

Parameters:
g - Graphics object.
r - row number.
 o paintColHeader
 protected void paintColHeader(Graphics g,
                               int c)
Paint the specified column header cell if it's not empty.

Parameters:
g - Graphics object.
c - column number.

All Packages  Class Hierarchy  This Package  Previous  Next  Index