The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet. This arranges data in a tabular form.
Constructors in JTable:
- JTable(): A table is created with empty cells.
- JTable(int rows, int cols): Creates a table of size rows * cols.
- JTable(Object data, Object Column): A table is created with the specified name where Column defines the column names.
Functions in JTable:
- addColumn(TableColumn column) : adds a column at the end of the JTable.
- clearSelection() : Selects all the selected rows and columns.
- editCellAt(int row, int col) : edits the intersecting cell of the column number col and row number row programmatically, if the given indices are valid and the corresponding cell is editable.
- setValueAt(Object value, int row, int col) : Sets the cell value as ‘value’ for the position row, col in the JTable.
Below is the program to illustrate the various methods of JTable:
- Java Swing | Translucent and shaped Window in Java
- Java Swing | JPopupMenu
- JLabel | Java Swing
- Java Swing | MatteBorder
- Java Swing | JTextArea
- Java Swing | JSlider
- Java Swing | ToolTip
- JRadioButton | Java Swing
- Java Swing | JToolBar
- Java Swing | JMenuBar
- Java Swing | JProgressBar
- Java Swing | JTextField
- Java Swing | Look and Feel
- Java Swing | JFileChooser
- Java Swing | JSpinner
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.