Java Swing | JTable Last Updated : 12 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // Packages to import import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class JTableExamples { // frame JFrame f; // Table JTable j; // Constructor JTableExamples() { // Frame initialization f = new JFrame(); // Frame Title f.setTitle("JTable Example"); // Data to be displayed in the JTable String[][] data = { { "Kundan Kumar Jha", "4031", "CSE" }, { "Anand Jha", "6014", "IT" } }; // Column Names String[] columnNames = { "Name", "Roll Number", "Department" }; // Initializing the JTable j = new JTable(data, columnNames); j.setBounds(30, 40, 200, 300); // adding it to JScrollPane JScrollPane sp = new JScrollPane(j); f.add(sp); // Frame Size f.setSize(500, 200); // Frame Visible = true f.setVisible(true); } // Driver method public static void main(String[] args) { new JTableExamples(); } } Output: Comment More infoAdvertise with us Next Article Java SE vs Java EE S ShivamKD Follow Improve Article Tags : Java java-swing Practice Tags : Java Similar Reads Java JTabbedPane JTabbedPane is a GUI(Graphical User Interface) component in the Java Swing library that allows you to create a tabbed pane interface. A tabbed pane is a container that can store and organize multiple components into distinct tabs. It contains a collection of tabs. When you click on a tab, only data 5 min read Java JTree The JTree is a type of GUI(Graphic User Interface) that displays information in a hierarchical way. This intricate component part provides a quite elegant substance of representing relationships among elements in a tree-like structure. In this exploration, we'll delve into the essence of the JTree c 2 min read Java SE vs Java EE Java is a highly popular and versatile programming language used globally to create various applications. Two major Java platforms are Java SE (Standard Edition) and Java EE (Enterprise Edition). Understanding the differences between these platforms is crucial for developers working on enterprise-le 5 min read Java Swing | JList with examples JList is part of Java Swing package . JList is a component that displays a set of Objects and allows the user to select one or more items . JList inherits JComponent class. JList is a easy way to display an array of Vectors .Constructor for JList are : JList(): creates an empty blank listJList(E [ ] 4 min read Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Hashtable in Java Hashtable class, introduced as part of the Java Collections framework, implements a hash table that maps keys to values. Any non-null object can be used as a key or as a value. To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method an 12 min read Like