Java javax.swing JTable fields, constructors, methods, implement or subclass

Example usage for Java javax.swing JTable fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for javax.swing JTable.

The text is from its open source code.

Subclass

javax.swing.JTable has subclasses.
Click this link to see all its subclasses.

Field

intAUTO_RESIZE_OFF
Do not adjust column widths automatically; use a horizontal scrollbar instead.
intAUTO_RESIZE_NEXT_COLUMN
When a column is adjusted in the UI, adjust the next column the opposite way.
intAUTO_RESIZE_SUBSEQUENT_COLUMNS
During UI adjustment, change subsequent columns to preserve the total width; this is the default behavior.
intAUTO_RESIZE_LAST_COLUMN
During all resize operations, apply adjustments to the last column only.
intAUTO_RESIZE_ALL_COLUMNS
During all resize operations, proportionately resize all columns.

Constructor

JTable()
Constructs a default JTable that is initialized with a default data model, a default column model, and a default selection model.
JTable(TableModel dm, TableColumnModel cm)
Constructs a JTable that is initialized with dm as the data model, cm as the column model, and a default selection model.
JTable(int numRows, int numColumns)
Constructs a JTable with numRows and numColumns of empty cells using DefaultTableModel.
JTable(Vector rowData, Vector columnNames)
Constructs a JTable to display the values in the Vector of Vectors, rowData, with column names, columnNames.
JTable(final Object[][] rowData, final Object[] columnNames)
Constructs a JTable to display the values in the two dimensional array, rowData, with column names, columnNames.
JTable(TableModel dm)
Constructs a JTable that is initialized with dm as the data model, a default column model, and a default selection model.

Method

Componentadd(Component comp)
Appends the specified component to the end of this container.
voidaddColumn(TableColumn aColumn)
Appends aColumn to the end of the array of columns held by this JTable's column model.
voidaddColumnSelectionInterval(int index0, int index1)
Adds the columns from index0 to index1, inclusive, to the current selection.
voidaddComponentListener(ComponentListener l)
Adds the specified component listener to receive component events from this component.
voidaddFocusListener(FocusListener l)
Adds the specified focus listener to receive focus events from this component when this component gains input focus.
voidaddKeyListener(KeyListener l)
Adds the specified key listener to receive key events from this component.
voidaddMouseListener(MouseListener l)
Adds the specified mouse listener to receive mouse events from this component.
voidaddMouseMotionListener(MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse motion events from this component.
voidaddNotify()
Calls the configureEnclosingScrollPane method.
voidaddRowSelectionInterval(int index0, int index1)
Adds the rows from index0 to index1, inclusive, to the current selection.
voidchangeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
Updates the selection models of the table, depending on the state of the two flags: toggle and extend.
voidclearSelection()
Deselects all selected columns and rows.
intcolumnAtPoint(Point point)
Returns the index of the column that point lies in, or -1 if the result is not in the range [0, getColumnCount()-1].
intconvertColumnIndexToModel(int viewColumnIndex)
Maps the index of the column in the view at viewColumnIndex to the index of the column in the table model.
intconvertColumnIndexToView(int modelColumnIndex)
Maps the index of the column in the table model at modelColumnIndex to the index of the column in the view.
intconvertRowIndexToModel(int viewRowIndex)
Maps the index of the row in terms of the view to the underlying TableModel.
intconvertRowIndexToView(int modelRowIndex)
Maps the index of the row in terms of the TableModel to the view.
voidcreateDefaultColumnsFromModel()
Creates default columns for the table from the data model using the getColumnCount method defined in the TableModel interface.
voiddoLayout()
Causes this table to lay out its rows and columns.
booleaneditCellAt(int row, int column)
Programmatically starts editing the cell at row and column, if those indices are in the valid range, and the cell at those indices is editable.
voideditingStopped(ChangeEvent e)
Invoked when editing is finished.
booleanequals(Object obj)
Indicates whether some other object is "equal to" this one.
ActionMapgetActionMap()
Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding.
booleangetAutoCreateColumnsFromModel()
Determines whether the table will create default columns from the model.
intgetAutoResizeMode()
Returns the auto resize mode of the table.
booleangetAutoscrolls()
Gets the autoscrolls property.
ColorgetBackground()
Gets the background color of this component.
BordergetBorder()
Returns the border of this component or null if no border is currently set.
RectanglegetBounds()
Gets the bounds of this component in the form of a Rectangle object.
TableCellEditorgetCellEditor()
Returns the active cell editor, which is null if the table is not currently editing.
TableCellEditorgetCellEditor(int row, int column)
Returns an appropriate editor for the cell specified by row and column.
RectanglegetCellRect(int row, int column, boolean includeSpacing)
Returns a rectangle for the cell that lies at the intersection of row and column.
TableCellRenderergetCellRenderer(int row, int column)
Returns an appropriate renderer for the cell specified by this row and column.
booleangetCellSelectionEnabled()
Returns true if both row and column selection models are enabled.
ObjectgetClientProperty(Object key)
Returns the value of the property with the specified key.
TableColumngetColumn(Object identifier)
Returns the TableColumn object for the column in the table whose identifier is equal to identifier, when compared using equals.
ClassgetColumnClass(int column)
Returns the type of the column appearing in the view at column position column.
intgetColumnCount()
Returns the number of columns in the column model.
TableColumnModelgetColumnModel()
Returns the TableColumnModel that contains all column information of this table.
StringgetColumnName(int column)
Returns the name of the column appearing in the view at column position column.
booleangetColumnSelectionAllowed()
Returns true if columns can be selected.
TableCellEditorgetDefaultEditor(Class columnClass)
Returns the editor to be used when no editor has been set in a TableColumn.
TableCellRenderergetDefaultRenderer(Class columnClass)
Returns the cell renderer to be used when no renderer has been set in a TableColumn.
intgetEditingColumn()
Returns the index of the column that contains the cell currently being edited.
intgetEditingRow()
Returns the index of the row that contains the cell currently being edited.
ComponentgetEditorComponent()
Returns the component that is handling the editing session.
FontgetFont()
Gets the font of this component.
FontMetricsgetFontMetrics(Font font)
Gets the FontMetrics for the specified Font.
ColorgetForeground()
Gets the foreground color of this component.
GraphicsgetGraphics()
Returns this component's graphics context, which lets you draw on a component.
intgetHeight()
Returns the current height of this component.
InputMapgetInputMap(int condition)
Returns the InputMap that is used during condition.
InsetsgetInsets()
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
DimensiongetIntercellSpacing()
Returns the horizontal and vertical space between cells.
LocalegetLocale()
Gets the locale of this component.
PointgetLocationOnScreen()
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.
DimensiongetMaximumSize()
If the maximum size has been set to a non-null value just returns it.
TableModelgetModel()
Returns the TableModel that provides the data displayed by this JTable .
MouseListener[]getMouseListeners()
Returns an array of all the mouse listeners registered on this component.
StringgetName()
Gets the name of the component.
ContainergetParent()
Gets the parent of this component.
DimensiongetPreferredScrollableViewportSize()
Returns the preferred size of the viewport for this table.
DimensiongetPreferredSize()
If the preferredSize has been set to a non-null value just returns it.
intgetRowCount()
Returns the number of rows that can be shown in the JTable, given unlimited space.
intgetRowHeight()
Returns the height of a table row, in pixels.
intgetRowHeight(int row)
Returns the height, in pixels, of the cells in row.
intgetRowMargin()
Gets the amount of empty space, in pixels, between cells.
booleangetRowSelectionAllowed()
Returns true if rows can be selected.
RowSortergetRowSorter()
Returns the object responsible for sorting.
intgetSelectedColumn()
Returns the index of the first selected column, -1 if no column is selected.
intgetSelectedColumnCount()
Returns the number of selected columns.
int[]getSelectedColumns()
Returns the indices of all selected columns.
intgetSelectedRow()
Returns the index of the first selected row, -1 if no row is selected.
intgetSelectedRowCount()
Returns the number of selected rows.
int[]getSelectedRows()
Returns the indices of all selected rows.
ColorgetSelectionBackground()
Returns the background color for selected cells.
ColorgetSelectionForeground()
Returns the foreground color for selected cells.
ListSelectionModelgetSelectionModel()
Returns the ListSelectionModel that is used to maintain row selection state.
DimensiongetSize()
Returns the size of this component in the form of a Dimension object.
JTableHeadergetTableHeader()
Returns the tableHeader used by this JTable.
ObjectgetValueAt(int row, int column)
Returns the cell value at row and column.
RectanglegetVisibleRect()
Returns the Component's "visible rectangle" - the intersection of this component's visible rectangle, new Rectangle(0, 0, getWidth(), getHeight()), and all of its ancestors' visible rectangles.
intgetWidth()
Returns the current width of this component.
booleanisCellEditable(int row, int column)
Returns true if the cell at row and column is editable.
booleanisCellSelected(int row, int column)
Returns true if the specified indices are in the valid range of rows and columns and the cell at the specified position is selected.
booleanisEditing()
Returns true if a cell is being edited.
booleanisEnabled()
Determines whether this component is enabled.
booleanisOpaque()
Returns true if this component is completely opaque.
booleanisRowSelected(int row)
Returns true if the specified index is in the valid range of rows, and the row at that index is selected.
voidmoveColumn(int column, int targetColumn)
Moves the column column to the position currently occupied by the column targetColumn in the view.
voidpaint(Graphics g)
Invoked by Swing to draw components.
ComponentprepareRenderer(TableCellRenderer renderer, int row, int column)
Prepares the renderer by querying the data model for the value and selection state of the cell at row, column.
booleanprint()
A convenience method that displays a printing dialog, and then prints this JTable in mode PrintMode.FIT_WIDTH, with no header or footer text.
booleanprint(PrintMode printMode)
A convenience method that displays a printing dialog, and then prints this JTable in the given printing mode, with no header or footer text.
booleanprint(PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat)
A convenience method that displays a printing dialog, and then prints this JTable in the given printing mode, with the specified header and footer text.
booleanprint(PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintRequestAttributeSet attr, boolean interactive)
Prints this table, as specified by the fully featured #print(JTable.PrintMode,MessageFormat,MessageFormat,boolean,PrintRequestAttributeSet,boolean,PrintService) print method, with the default printer specified as the print service.
voidputClientProperty(Object key, Object value)
Adds an arbitrary key/value "client property" to this component.
voidremoveColumn(TableColumn aColumn)
Removes aColumn from this JTable's array of columns.
voidremoveColumnSelectionInterval(int index0, int index1)
Deselects the columns from index0 to index1, inclusive.
voidremoveMouseListener(MouseListener l)
Removes the specified mouse listener so that it no longer receives mouse events from this component.
voidremoveRowSelectionInterval(int index0, int index1)
Deselects the rows from index0 to index1, inclusive.
voidrepaint()
Repaints this component.
booleanrequestFocusInWindow()
Requests that this Component gets the input focus.
voidrevalidate()
Supports deferred automatic layout.
introwAtPoint(Point point)
Returns the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1].
voidscrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the JComponent's parent.
voidselectAll()
Selects all rows, columns, and cells in the table.
voidsetAlignmentX(float alignmentX)
Sets the horizontal alignment.
voidsetAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel)
Sets this table's autoCreateColumnsFromModel flag.
voidsetAutoCreateRowSorter(boolean autoCreateRowSorter)
Specifies whether a RowSorter should be created for the table whenever its model changes.
voidsetAutoResizeMode(int mode)
Sets the table's auto resize mode when the table is resized.
voidsetBackground(Color bg)
Sets the background color of this component.
voidsetBorder(Border border)
Sets the border of this component.
voidsetBounds(int x, int y, int width, int height)
Moves and resizes this component.
voidsetBounds(Rectangle r)
Moves and resizes this component to conform to the new bounding rectangle r .
voidsetCellEditor(TableCellEditor anEditor)
Sets the active cell editor.
voidsetCellSelectionEnabled(boolean cellSelectionEnabled)
Sets whether this table allows both a column selection and a row selection to exist simultaneously.
voidsetColumnModel(final TableColumnModel columnModel)
Sets the column model for this table to columnModel and registers for listener notifications from the new column model.
voidsetColumnSelectionAllowed(boolean columnSelectionAllowed)
Sets whether the columns in this model can be selected.
voidsetColumnSelectionInterval(int index0, int index1)
Selects the columns from index0 to index1, inclusive.
voidsetComponentOrientation(ComponentOrientation o)
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.
voidsetComponentPopupMenu(JPopupMenu popup)
Sets the JPopupMenu for this JComponent.
voidsetCursor(Cursor cursor)
Sets the cursor image to the specified cursor.
voidsetDefaultEditor(Class columnClass, TableCellEditor editor)
Sets a default cell editor to be used if no editor has been set in a TableColumn.
voidsetDefaultRenderer(Class columnClass, TableCellRenderer renderer)
Sets a default cell renderer to be used if no renderer has been set in a TableColumn.
voidsetDoubleBuffered(boolean aFlag)
Sets whether this component should use a buffer to paint.
voidsetDragEnabled(boolean b)
Turns on or off automatic drag handling.
voidsetDropMode(DropMode dropMode)
Sets the drop mode for this component.
voidsetDropTarget(DropTarget dt)
Associate a DropTarget with this component.
voidsetEnabled(boolean enabled)
Sets whether or not this component is enabled.
voidsetFillsViewportHeight(boolean fillsViewportHeight)
Sets whether or not this table is always made large enough to fill the height of an enclosing viewport.
voidsetFocusable(boolean focusable)
Sets the focusable state of this Component to the specified value.
voidsetFocusTraversalKeys(int id, Set keystrokes)
Sets the focus traversal keys for a given traversal operation for this Component.
voidsetFont(Font font)
Sets the font for this component.
voidsetForeground(Color fg)
Sets the foreground color of this component.
voidsetGridColor(Color gridColor)
Sets the color used to draw grid lines to gridColor and redisplays.
voidsetIntercellSpacing(Dimension intercellSpacing)
Sets the rowMargin and the columnMargin -- the height and width of the space between cells -- to intercellSpacing.
voidsetMaximumSize(Dimension maximumSize)
Sets the maximum size of this component to a constant value.
voidsetModel(final TableModel dataModel)
Sets the data model for this table to dataModel and registers with it for listener notifications from the new data model.
voidsetName(String name)
Sets the name of the component to the specified string.
voidsetOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds.
voidsetPreferredScrollableViewportSize(Dimension size)
Sets the preferred size of the viewport for this table.
voidsetPreferredSize(Dimension preferredSize)
Sets the preferred size of this component.
voidsetRowHeight(int rowHeight)
Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints.
voidsetRowHeight(int row, int rowHeight)
Sets the height for row to rowHeight, revalidates, and repaints.
voidsetRowMargin(int rowMargin)
Sets the amount of empty space between cells in adjacent rows.
voidsetRowSelectionAllowed(boolean rowSelectionAllowed)
Sets whether the rows in this model can be selected.
voidsetRowSelectionInterval(int index0, int index1)
Selects the rows from index0 to index1, inclusive.
voidsetRowSorter(RowSorter sorter)
Sets the RowSorter.
voidsetSelectionBackground(Color selectionBackground)
Sets the background color for selected cells.
voidsetSelectionMode(int selectionMode)
Sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals.
voidsetSelectionModel(final ListSelectionModel selectionModel)
Sets the row selection model for this table to selectionModel and registers for listener notifications from the new selection model.
voidsetShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
voidsetShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
voidsetShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.
voidsetSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke)
Sets whether editors in this JTable get the keyboard focus when an editor is activated as a result of the JTable forwarding keyboard events for a cell.
voidsetTableHeader(JTableHeader tableHeader)
Sets the tableHeader working with this JTable to newHeader.
voidsetToolTipText(String text)
Registers the text to display in a tool tip.
voidsetTransferHandler(TransferHandler newHandler)
Sets the TransferHandler , which provides support for transfer of data into and out of this component via cut/copy/paste and drag and drop.
voidsetUpdateSelectionOnSort(boolean update)
Specifies whether the selection should be updated after sorting.
voidsetValueAt(Object aValue, int row, int column)
Sets the value for the cell in the table model at row and column.
voidsetVisible(boolean aFlag)
Makes the component visible or invisible.
voidtableChanged(TableModelEvent e)
Invoked when this table's TableModel generates a TableModelEvent.
voidupdate(Graphics g)
Calls paint.
voidupdateUI()
Notification from the UIManager that the L&F has changed.
voidvalidate()
Validates this container and all of its subcomponents.