Here we list the main methods associated with the JTable:
The public static JScrollPane createScrollPaneForTable(JTable aTable) method creates in instance of a JScrollPane object and attaches it to the JTable object.
The following methods manage the header associated with the JTable object. The table header object holds information about the columns and their characteristics:
public void setTableHeader(JTableHeader newHeader) public JTableHeader getTableHeader()
The following methods manage the height of the rows within the JTable object. A custom cell renderer can override the row height:
public void setRowHeight(int newHeight) public int getRowHeight()
The methods below manage the space between cells within the table. Note that The intercell spacing can be overridden by a custom cell renderer.
public void setIntercellSpacing(Dimension newSpacing) public Dimension getIntercellSpacing()
The following methods control the colour of the grid lines and determine if the grid lines are visible within the table. The grid lines in the horizontal and vertical planes are individually configurable with methods from this group.
public void setGridColor(Color newColor) public Color getGridColor() public void setShowGrid(boolean b) public void setShowHorizontalLines(boolean b) public void setShowVerticalLines(boolean b) public boolean getShowHorizontalLines() public boolean getShowVerticalLines()
The following methods controls the automatic sizing of columns: (This feature resizes the columns whenever the owner panel is resized.)
public void setAutoResizeMode(int mode) public int getAutoResizeMode() public void sizeColumnsToFit(boolean lastColumnOnly)
These methods manage the creation of columns within the table -- Columns can be generated automatically from the data model; however, column creation can be overridden if the developer manually creates them:
public void setAutoCreateColumnsFromModel(boolean createColumns) public boolean getAutoCreateColumnsFromModel() public void createDefaultColumnsFromModel()
The methods below return instances of the default model owned by the table object:
public void setDefaultRenderer( Class columnClass, TableCellRenderer renderer ) public TableCellRenderer getDefaultRenderer( Class columnClass ) public void setDefaultEditor( Class columnClass, TableCellEditor editor ) public TableCellEditor getDefaultEditor(Class columnClass)
The following methods manage all aspects of cell selection in a JTable instance. Selection resolution can be performed at the row, column, or individual cell level. Selections can be returned as a single item or an array of items.
public void setSelectionMode(int selectionMode) public void setRowSelectionAllowed(boolean flag) public void setColumnSelectionAllowed(boolean flag) public boolean getColumnSelectionAllowed() public void setCellSelectionEnabled(boolean flag) public boolean getCellSelectionEnabled() public void selectAll() public void clearSelection() public void setRowSelectionInterval( int index0, int index1 ) public void setColumnSelectionInterval( int index0, int index1 ) public void addRowSelectionInterval( int index0, int index1 ) public void addColumnSelectionInterval( int index0, int index1 ) public void removeRowSelectionInterval( int index0, int index1 ) public void removeColumnSelectionInterval( int index0, int index1 ) public int getSelectedRow() public int getSelectedColumn() public int[] getSelectedRows() public int[] getSelectedColumns() public int getSelectedRowCount() public int getSelectedColumnCount() public boolean isRowSelected(int row) public boolean isColumnSelected(int column) public boolean isCellSelected(int row, int column)
The methods below control the foreground and background colours used to identify the selected cells, rows, and columns within the JTable.
public Color getSelectionForeground() public void setSelectionForeground(Color selectionForeground) public Color getSelectionBackground() public void setSelectionBackground(Color selectionBackground)
The following method in this group are responsible for retrieving information about columns and for controlling the organization of columns within the table. Columns can be added, removed, or moved with these methods.
public TableColumn getColumn(Object identifier) public int convertColumnIndexToModel(int viewColumnIndex) public int convertColumnIndexToView(int modelColumnIndex) public String getColumnName(int column) public Class getColumnClass(int column) public void addColumn(TableColumn aColumn) public void removeColumn(TableColumn aColumn) public void moveColumn( int column, int targetColumn )
The methods below return the count of rows and columns within the JTable instance's data model:
public int getRowCount() public int getColumnCount()
The methods below are responsible for retrieving and setting the values of individual cells in the table. The cell location is identified by its row and column values.
public Object getValueAt( int row, int column ) public void setValueAt( Object aValue, int row, int column )
The following methods manage the editing features of the JTable class. Individual cells can be edited using either the default editor or one specified programmatically.
public boolean isCellEditable( int row, int column ) public boolean editCellAt( int row, int column ) public boolean editCellAt( int row, int column, EventObject e ) public boolean isEditing() public Component getEditorComponent() public int getEditingColumn() public int getEditingRow() public TableCellEditor getCellEditor() public void setCellEditor(TableCellEditor anEditor) public void setEditingColumn(int aColumn) public void setEditingRow(int aRow)
The final group of methods manage the models used by the JTable class. By default, the table will assign default model objects which can be retrieved with methods from this group, or new custom models can be attached to the table.
public void setModel(TableModel newModel) public TableModel getModel() public void setColumnModel(TableColumnModel newModel) public TableColumnModel getColumnModel() public void setSelectionModel(ListSelectionModel newModel) public ListSelectionModel getSelectionModel()