|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object buoy.event.EventSource buoy.widget.Widget buoy.widget.BTable
public class BTable
A BTable is a Widget that displays a grid of objects. Typically the objects are Strings, but other types of objects can be used as well. It optionally can allow the user to select rows, columns, or individual cells, and to edit the contents of cells. There are methods for adding and removing rows and columns, and for setting the contents of cells. Alternatively, you can set a TableModel to provide more complex behaviors.
BTable does not provide scrolling automatically. Normally, it is used inside a BScrollPane. When a
BTable is set as the content of a BScrollPane, it automatically places its column headers (which are
represented by a separate Widget) into the BScrollPane's column header position. When using a BTable
outside a BScrollPane, you will need to call getTableHeader()
to get the Widget representing the column headers, and position it separately.
You may also want to access the column headers directly, in order to respond to events in the headers. For example, suppose you want mouse clicks in a column header to select the clicked column, and deselect all other columns. This is done by adding an event listener to the header Widget:
table.getTableHeader().addEventLink(MousePressedEvent.class, new Object() { void processEvent(MousePressedEvent ev) { table.clearSelection(); table.setColumnSelected(table.findColumn(ev.getPoint()), true); } });
A BTable can optionally allow the user to reorder the columns by dragging their headers. This affects only the display of the table, not the internal data representation. Whenever a method takes a column index as an argument, that index refers to the internal ordering, not to the display order. Therefore, any reordering of columns by the user will be completely invisible to the program, and can be ignored.
A BTable is a wrapper around a JTable and its associated classes, which together form a powerful but
also very complex API. BTable exposes only the most commonly used features of this API. To use other
features, call getComponent()
to get the underlying JTable, then manipulate it directly.
For example, you can set a custom TableCellRenderer to customize the appearance of individual cells,
or set a TableCellEditor to control the user interface for editing cells.
In addition to the event types generated by all Widgets, BTables generate the following event types:
Nested Class Summary | |
---|---|
class |
BTable.BTableHeader
This inner class is the Widget that draws the table's column headers. |
static class |
BTable.SelectionMode
This inner class represents a selection mode. |
Field Summary | |
---|---|
static BTable.SelectionMode |
SELECT_CELLS
|
static BTable.SelectionMode |
SELECT_COLUMNS
|
static BTable.SelectionMode |
SELECT_NONE
|
static BTable.SelectionMode |
SELECT_ROWS
|
Constructor Summary | |
---|---|
BTable()
Create a BTable with no rows or columns. |
|
BTable(int rows,
int cols)
Create an empty BTable of a specified size. |
|
BTable(java.lang.Object[][] cellData,
java.lang.Object[] columnTitle)
Create a BTable, and populate it with the data in an array. |
|
BTable(javax.swing.table.TableModel model)
Create a BTable whose contents are determined by a TableModel. |
Method Summary | |
---|---|
void |
addColumn(java.lang.Object columnTitle)
Add a column to this table. |
void |
addColumn(java.lang.Object columnTitle,
java.lang.Object[] columnData)
Add a column to the end of this table. |
void |
addRow(int index,
java.lang.Object[] rowData)
Add a row to the table. |
void |
addRow(java.lang.Object[] rowData)
Add a row to the end of the table. |
void |
clearSelection()
Deselect all rows and columns. |
void |
editCellAt(int row,
int col)
Programmatically begin editing a specified cell, if editing is allowed. |
int |
findColumn(java.awt.Point pos)
Given a Point which represents a pixel location, find which column the Point lies on. |
int |
findRow(java.awt.Point pos)
Given a Point which represents a pixel location, find which row the Point lies on. |
java.lang.Object |
getCellValue(int row,
int col)
Get the value contained in a cell. |
int |
getColumnCount()
Get the number of columns in the table. |
java.lang.Object |
getColumnHeader(int col)
Get the header value for a column. |
boolean |
getColumnsReorderable()
Get whether the user is allowed to reorder columns by dragging their headers. |
boolean |
getColumnsResizable()
Get whether the user is allowed to resize columns by clicking between the headers and dragging. |
int |
getColumnWidth(int col)
Get the width of a column. |
javax.swing.JTable |
getComponent()
Get the java.awt.Component corresponding to this Widget. |
javax.swing.table.TableModel |
getModel()
Get the TableModel which controls the contents of this BTable. |
int |
getRowCount()
Get the number of rows in the table. |
int |
getRowHeight(int row)
Get the height of a row. |
java.awt.Point[] |
getSelectedCells()
Get an array of Points which contain the indices of all selected cells. |
int[] |
getSelectedColumns()
Get an array which contains the indices of all selected columns. |
int[] |
getSelectedRows()
Get an array which contains the indices of all selected rows. |
BTable.SelectionMode |
getSelectionMode()
Get the selection mode for this table. |
boolean |
getShowHorizontalLines()
Get whether this table displays horizontal lines between the rows. |
boolean |
getShowVerticalLines()
Get whether this table displays vertical lines between the columns. |
BTable.BTableHeader |
getTableHeader()
Get the Widget that displays this table's column headers. |
boolean |
isCellSelected(int row,
int col)
Determine whether a cell is selected. |
boolean |
isColumnEditable(int index)
Determine whether the cells in a particular column may be edited. |
boolean |
isColumnSelected(int col)
Determine whether a column is selected. |
boolean |
isMultipleSelectionEnabled()
Determine whether this table allows multiple cells to be selected. |
boolean |
isRowSelected(int row)
Determine whether a row is selected. |
void |
removeAllColumns()
Remove all columns from this table. |
void |
removeAllRows()
Remove all rows from the table. |
void |
removeColumn(int index)
Remove a column from this table. |
void |
removeRow(int index)
Remove a row from the table. |
void |
scrollToCell(int row,
int col)
Scroll the BTable's parent BScrollPane to ensure that a particular cell is visible. |
void |
setCellSelected(int row,
int col,
boolean selected)
Set whether a cell is selected. |
void |
setCellValue(int row,
int col,
java.lang.Object value)
Set the value contained in a cell. |
void |
setColumnEditable(int index,
boolean editable)
Set whether the cells in a particular column may be edited. |
void |
setColumnHeader(int col,
java.lang.Object value)
Set the header value for a column. |
void |
setColumnSelected(int col,
boolean selected)
Set whether a column is selected. |
void |
setColumnsReorderable(boolean reorderable)
Set whether the user is allowed to reorder columns by dragging their headers. |
void |
setColumnsResizable(boolean resizable)
Set whether the user is allowed to resize columns by clicking between the headers and dragging. |
void |
setColumnWidth(int col,
int width)
Set the width of a column. |
void |
setModel(javax.swing.table.TableModel model)
Set the TableModel which controls the contents of this BTable. |
void |
setMultipleSelectionEnabled(boolean multiple)
Set whether this table should allow multiple cells to be selected. |
void |
setRowHeight(int row,
int height)
Set the height of a row. |
void |
setRowSelected(int row,
boolean selected)
Set whether a row is selected. |
void |
setSelectionMode(BTable.SelectionMode mode)
Set the selection mode for this table. |
void |
setShowHorizontalLines(boolean show)
Set whether this table displays horizontal lines between the rows. |
void |
setShowVerticalLines(boolean show)
Set whether this table displays vertical lines between the columns. |
void |
sizeColumnToFit(int col)
Adjust the width of a column based on the size of its header. |
Methods inherited from class buoy.widget.Widget |
---|
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible |
Methods inherited from class buoy.event.EventSource |
---|
addEventLink, addEventLink, removeEventLink |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final BTable.SelectionMode SELECT_NONE
public static final BTable.SelectionMode SELECT_ROWS
public static final BTable.SelectionMode SELECT_COLUMNS
public static final BTable.SelectionMode SELECT_CELLS
Constructor Detail |
---|
public BTable()
public BTable(int rows, int cols)
rows
- the number of rowscols
- the number of columnspublic BTable(java.lang.Object[][] cellData, java.lang.Object[] columnTitle)
cellData
- element [i][j] is the object to display in row i, column jcolumnTitle
- the list of column titles (usually Strings)public BTable(javax.swing.table.TableModel model)
Method Detail |
---|
public javax.swing.JTable getComponent()
Widget
getComponent
in class Widget
public BTable.BTableHeader getTableHeader()
public javax.swing.table.TableModel getModel()
public void setModel(javax.swing.table.TableModel model)
public void addColumn(java.lang.Object columnTitle)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
columnTitle
- the title of the column to add (usually a String)public void addColumn(java.lang.Object columnTitle, java.lang.Object[] columnData)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
columnTitle
- the title of the column to add (usually a String)columnData
- the objects to display in the cells of the new columnpublic void removeColumn(int index)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
index
- the index of the column to removepublic void removeAllColumns()
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
public void addRow(java.lang.Object[] rowData)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
rowData
- the objects to display in the cells of the new rowpublic void addRow(int index, java.lang.Object[] rowData)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
index
- the position at which to add the rowrowData
- the objects to display in the cells of the new rowpublic void removeRow(int index)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
index
- the index of the row to removepublic void removeAllRows()
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
public int getRowCount()
public int getColumnCount()
public boolean isColumnEditable(int index)
If you have set a custom model for this table, either by passing it to the constructor or by calling setModel(), the value returned by this method is meaningless and should be ignored.
index
- the index of the columnpublic void setColumnEditable(int index, boolean editable)
This method works by manipulating the default TableModel for this table. If you have set a custom model, either by passing it to the constructor or by calling setModel(), this method has no effect.
index
- the index of the columneditable
- specifies whether cells in the column may be editedpublic java.lang.Object getCellValue(int row, int col)
row
- the row containing the cellcol
- the column containing the cellpublic void setCellValue(int row, int col, java.lang.Object value)
row
- the row containing the cellcol
- the column containing the cellvalue
- the value to place into the cellpublic java.lang.Object getColumnHeader(int col)
col
- the column indexpublic void setColumnHeader(int col, java.lang.Object value)
col
- the column indexvalue
- the value to place into the column headerpublic int getRowHeight(int row)
row
- the row indexpublic void setRowHeight(int row, int height)
row
- the row indexheight
- the new height for the rowpublic int getColumnWidth(int col)
col
- the column indexpublic void setColumnWidth(int col, int width)
col
- the column indexwidth
- the new width for the columnpublic void sizeColumnToFit(int col)
col
- the column indexpublic boolean getColumnsResizable()
public void setColumnsResizable(boolean resizable)
public boolean getColumnsReorderable()
public void setColumnsReorderable(boolean reorderable)
public BTable.SelectionMode getSelectionMode()
public void setSelectionMode(BTable.SelectionMode mode)
public boolean isMultipleSelectionEnabled()
public void setMultipleSelectionEnabled(boolean multiple)
public boolean isRowSelected(int row)
If the selection mode is SELECT_COLUMNS, the value returned by this method is meaningless and should be ignored.
row
- the row indexpublic void setRowSelected(int row, boolean selected)
row
- the row indexselected
- specifies whether the row should be selectedpublic int[] getSelectedRows()
If the selection mode is SELECT_COLUMNS, the value returned by this method is meaningless and should be ignored.
public boolean isColumnSelected(int col)
If the selection mode is SELECT_ROWS, the value returned by this method is meaningless and should be ignored.
col
- the column indexpublic void setColumnSelected(int col, boolean selected)
col
- the column indexselected
- specifies whether the column should be selectedpublic int[] getSelectedColumns()
If the selection mode is SELECT_ROWS, the value returned by this method is meaningless and should be ignored.
public boolean isCellSelected(int row, int col)
row
- the row indexcol
- the column indexpublic void setCellSelected(int row, int col, boolean selected)
row
- the row indexcol
- the column indexselected
- specifies whether the cell should be selectedpublic java.awt.Point[] getSelectedCells()
public void clearSelection()
public int findRow(java.awt.Point pos)
pos
- the point of interest
public int findColumn(java.awt.Point pos)
pos
- the point of interest
public void editCellAt(int row, int col)
row
- the row containing the cellcol
- the column containing the cellpublic boolean getShowHorizontalLines()
public void setShowHorizontalLines(boolean show)
public boolean getShowVerticalLines()
public void setShowVerticalLines(boolean show)
public void scrollToCell(int row, int col)
row
- the row containing the cellcol
- the column containing the cell
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |