Default User Interaction · User Interaction Customization · List Mode
Table Scrolling · Row and Column Resizing · Cell Traversal
Cell Editing · Cell Selection · Mouse Pointers
This chapter describes the user-interaction features of JClass LiveTable Pro: how a user can interact with the table and how an application can control interaction.
![]() ![]() |
An application can be notified as a user interacts with the component by registering event listener routines that are called before, during, and after user interaction. Each event listener routine can affect each interaction in such ways as disallowing or constraining it. See the section for each interaction type for further details on using its event listener.
The default setting for the Mode property is JCTblEnum.MODE_TABLE.
By using the JumpScroll property, you can control the scrolling behavior of each scrollbar. Scrollbars can either scroll smoothly or "jump" scroll in whole row/column increments.
Both the TopRow and LeftColumn properties are updated dynamically as a table is scrolled.
JClass LiveTable Pro also scrolls the table when requested by other interactions, such as cell traversal and cell selection. Scrolling does not change the location of the current cell.
HorizSBPosition sets how the horizontal scrollbar is attached to the table. Similarly, VertSBPosition sets how the vertical scrollbar is attached to the table. When set to JCTblEnum.SBPOSITION_CELLS (default), the scrollbar is attached to the cell/label viewport (i.e. the cells that are visible). When set to JCTblEnum.SBPOSITION_SIDE, the scrollbar is attached to the side of the table (i.e. the whole of the table).
HorizSBAttachment sets how the end of the horizontal scrollbar is attached to the table. When set to JCTblEnum.ATTACH_CELLS (default), the scrollbar ends at the edge of the visible cells. When set to JCTblEnum.ATTACH_SIDE , the scrollbar ends at the edge of the table.
To specify standard-style table scrollbars:
To specify list-style table scrollbars:
HorizSBOffset and VertSBOffset specify the offset between the scrollbars and the table (default: 6 pixels). This offset usually applies to the space between the scrollbars and the table's cells/labels. However, when the scrollbars are attached to the side of the component, it can also apply to the space between the scrollbars and the side of the component, and only when there is space between the last row/column and the edge of the component.
Component c[] = table.getComponents(); for (int i = 0; i < c.length; i++) { if (c[i] == null) continue; if (c[i] instanceof TblVertScrollbar) { ((TblScrollbar)c[i]).setBackground(Color.red); break; } }
Remove the scrollbars from the screen by setting set HorizSBDisplay and/or VertSBDisplay to JCTblEnum.SBDISPLAY_NEVER.
To fully disable any and all scrolling, an application should also ensure that the user cannot select cells or traverse to cells outside the visible area.
The example below shows how to use the scrollBegin() and scrollEnd() scrollbar interface methods to store an internal state:
public void scrollBegin(JCScrollEvent ev) { if (ev.getDirection() == TblScrollbar.HORIZONTAL) hScrollingActive = true; else if (ev.getDirection() == TblScrollbar.VERTICAL) vScrollingActive = true; } public void scrollEnd(JCScrollEvent ev) { if (ev.getDirection() == TblScrollbar.HORIZONTAL) hScrollingActive = false; else if (ev.getDirection() == TblScrollbar.VERTICAL) vScrollingActive = false; }
To set the event listener for this event, use the following code:
table.addScrollListener(this);
JCResizeCellEvent uses the method getParam(), which retrieves the interactive resize stage. getParam() retrieves one of the following string values:
In addition to getParam(), there are other methods/properties available to JCResizeCellEvent. AllowResize determines whether an interactive resize is allowed (default: true),
The getColumn() method gets the column being resized. The getCurrentColumnWidth() and getCurrentRowHeight() methods get the current column width and the current row height respectively. The NewColumnWidth and NewRowHeight properties can set and retrieve information on the new column width and the new row height respectively.
As a cell is resized by the user, a JCResizeCellEvent is triggered, resizeCellBegin() is sent the initial values (as specified by getCurrentColumnWidth() and getCurrentColumnHeight()). When the user commits the change by releasing the mouse button, the end value from resizeCellEnd() is sent to setNewColumnWidth() and setNewRowHeight().
The following example event listener routine sets the width of any resized column to an increment of 10 pixels:
public void resizeCellBegin(JCResizeCellEvent ev) {} public void resizeCellEnd(JCResizeCellEvent ev) { ev.setNewColumnWidth(ev.getNewColumnWidth() / 10 * 10); }
To register the above event listener routine, use the following call:
table.addResizeCellListener(this);
![]() |
The cell validation and cell entry stages are detailed processes of their own, and are discussed separately.
Note that when users are allowed to select cells (specified with SelectionPolicy), a traversal internally triggers JCSelectEvent event listeners.
Disabling traversal also disables cell editability regardless of the setting of the Editable property.
The following code fragment sets all cells in row 3 to be non-traversable:
table.setTraversable(3, JCTblEnum.ALLCELLS, false); table.addTraverseCellListener(this); } int val = 0; public boolean handleEvent(Event event) { if (event.id == Event.ACTION_EVENT) { val++; if (val % 2 == 0) { JCVector cells = table.getCells(); for (int row = 3; row < 6; row++) { for (int col = 1; col < 4; col++) { ((JCVector)cells.elementAt(row)).setElementAt(col, null); } } table.setCells(cells); } else { for (int row = 3; row < 6; row++) { for (int col = 1; col < 4; col++) { table.setCell(row, col, null); } } } }
setMinCellVisibility() sets the minimum amount of a cell made visible when it is edited. When the table scrolls to edit a non-visible cell, this property determines the percentage of the cell that is scrolled into view. When set to 100, the cell is made completely visible. When set to 10, only 10% of the cell is made visible. If set to 0, the cell will not scroll to be made visible. This property affects the behavior of makeVisible().
You can use TRAVERSE_CELL, the ID variable of JCTraverseCellEvent to control interactive traversal. As a user traverses from one cell to another, this event is posted after a user has committed a cell edit, and before moving the Text component to the next cell. Each event listener is passed an object of type JCTraverseCellEvent.
JCTraverseCellEvent uses the getParam() method to retrieve information on the direction of the traversal. getParam() retrieves one of the following strings indicating the direction of traversal:
In addition to getParam(), there are several other properties available to JCResizeCellEvent. AllowResize determines whether an interactive resize is allowed (default: true). The getColumn() and getRow() methods gets the column and row of the current cell respectively. Finally, the NextColumn and NextRow properties respectively set or retrieve the column and row of the cell to traverse to.
The TRAVERSE_CELL action attempts to traverse to the cell specified by these members. Note that if NextColumn and NextRow reference a non-traversable cell, the traversal attempt will be unsuccessful. The following example code prevents the user from traversing outside of column 0:
public void traverseCell(JCTraverseCellEvent ev) { if (ev.getNextColumn() > 0) { if (ev.getRow() >= table.getNumRows()) ev.setNextRow(0); else ev.setNextRow(ev.getRow() + 1); ev.setNextColumn(0); } }
An application can control the following aspects of interactive cell editing on a cell-by-cell basis: editability, case, multi-line support, and maximum text length. An application can also control attributes and behavior of the current cell itself by programming the table's Text component.
table.commitEdit(true);
The boolean argument determines whether to hide the Text component. In this example, the edit will be committed and the Text component disappears.
Note that cells that you want a user to be able to edit must also be traversable (Traversable must be true).
The following example sets row 5 to non-editable (but traversable):
table.setEditable(4, JCTblEnum.ALLCELLS, false); table.addSelectListener(this); table.addEnterCellListener(this);
This property takes effect from the point it is set; it does not convert the case of previously-entered cell values.
![]() |
if (table.getTextComponent() != null) { table.getTextComponent().setBackground(Color.blue); table.getTextComponent().setForeground(Color.white); }
Consult your Java documentation for more information on programming TextComponent.
JCEnterCellEvent uses the getParam() method to retrieve information on the initiating action. getParam() retrieves one of the following strings indicating the direction of traversal:
In addition to getParam(), there are two other methods available to JCEnterCellEvent:getColumn() retrieves the column of the cell being traversed to, while getRow() retrieves the row of the cell being traversed to.
The following event listener routine sets the cell value to the current time when a user traverses to it:
public void enterCellBegin(JCEnterCellEvent ev) {}
JClass LiveTable Pro supports a number of selection policies, including multirange selection (selecting multiple ranges of cells), single range, single cell, and no selection.
![]() |
When SelectionPolicy is set to JCTblEnum.SELECT_NONE (default), JCSelectEvents are not posted as a user edits or attempts to select cells. Note that setting this property does not change the selected cell list.
Each range in the selected cell list is a JCCellRange structure. Its variables include:
start_column is the column of the first cell in range (top-left corner), while start_row is the first cell in range (top-left corner). end_column is the column of the last cell in a range (top-left corner), and end_row is the row of the last cell in range (bottom-right corner).
All members of the JCCellRange structure can be a row and column index. end_row and end_column can also be set to MAXINT , which specifies all of the cells in a row or column. Because the user can make a selection at any point and in any direction within a table, the start point is not necessarily the top-left corner of the range--it may be any of the four corners of a range.
The following example sets two selected ranges:
table.setSelectionPolicy(JCTblEnum.SELECT_MULTIRANGE); JCCellRange ranges[] = new JCCellRange[2]; ranges[0] = new JCCellRange(0, 0, 4, 2); ranges[1] = new JCCellRange(7, 1, 7, 4); JCVector v = new JCVector(ranges); table.setSelectedCells(v);
setSelectedBackground() determines the background color of selected cells, while setSelectedForeground() determines the foreground color of selected cells. By default, the default value for setSelectedBackground() is the cell's foreground color, while the default value for setSelectedForeground() is the cell's background color. When setSelectedBackground() is set to null, selected cells appear identical to unselected cells. When setSelectedForeground() is set to null and setSelectedBackground() is not null, the foreground of selected cells is the same as the foreground colors defined for the cells. This value is ignored when setSelectedBackground() is set to null.
public boolean getSelectedRange(int pos, JCCellRange range)
SelectedRange retrieves a currently-selected range from the SelectedCellList , and it can take the following parameters:
range is rationalized to read from top to bottom and from left to right, and special values such as MAXINT are converted to valid range values. SelectedRange returns false if no cells are selected, or if any argument is invalid.
The following example gets each selected range (assuming that selection policy is JCTblEnum.SELECT_MULTIRANGE):
int i = 0; JCCellRange r = new JCCellRange(); while (table.getSelectedRange(i++, r)) { System.out.println("Range " + i + " is (" + r.start_row + "," + r.start_column + ") to (" + r.end_row + "," + r.end_column + ")"); }
To determine whether a particular cell is selected, and retrieve the range if it is, call getSelectedCells(). This method has the following prototype:
public Vector getSelectedCells()
Each element of the Vector is an instance of a JCCellRange. This value is updated dynamically as a user selects cells. The selection policy controls the amount of selection allowed on the table, both by users and by the application. Users can select in any direction, so start_row and/or start_column may be greater than end_row and/or end_column . When a user clicks a row/column label to select an entire row or column, end_row or end_column is set to MAXINT.
JCCellRange nr = new JCCellRange(8, 1, 8, 4); Vector ve = table.getSelectedCells(); ve.addElement(nr); table.setSelectedCells(ve); return true; } return super.handleEvent(event);
The getAllowSelection() method determines whether the selection (or unselection) should be allowed (default: true). The Row and Column properties set or retrieve the respective value of the row or column being selected or unselected. The getEvent() method gets the event that initiated the action. The getStage() method retrieves the selection stage (either INITIAL or EXTEND), while getStateChange() returns the state change type generated by the event (either SELECTED or DESELECTED).
JCSelectListener is called before selection begins (selectBegin() ), and after a selection has finished (selectEnd()).
The following event listener routine constrains selection to the column where it started:
public void selectBegin(JCSelectEvent ev) { if (ev.getStage() == JCSelectEvent.INITIAL) { save_column = ev.getColumn(); } else if (ev.getStage() == JCSelectEvent.EXTEND) { if (ev.getColumn() != save_column) ev.setAllowSelection(false); } } public void selectEnd(JCSelectEvent ev) {} public boolean handleEvent(Event event) { if (event.id == Event.ACTION_EVENT) {
To select an entire row or column, set the Row or Column properties of JCSelectEvent to JCTblEnum.ALL. Note that you cannot set a RowLabel or ColumnLabel in this manner.
When tracking the mouse pointer, JClass LiveTable Pro considers the current settings of the Traversable and AllowCellResize properties.
1 Although scrollbars are removed, a user can still scroll with the keyboard. See "Disabling Interactive Scrolling" for complete information on disabling interactive scrolling.
2 Clicking on a label selects all of the cells in the row or column, not including the label.