«Back to Home

Core Java

Topics

JTable Class In Java

JTable Class
 
In Java, JTable class displays the data on two dimensional tables of cells.
 
Constructors of JTable class

JTable()

This constructor creates a table with the empty cells.
 
JTable(Object[][] rows, Object[] columns)

This constructor creates a table with the specific data.
 
Let’s see an example of JTable class, given below.
 
Code
  1. import javax.swing.*;  
  2. public class JTableExample {  
  3.     JFrame jf;  
  4.     JTableExample() {  
  5.         jf = new JFrame();  
  6.         String data[][] = {{"161""Bob""6000"},  
  7.         {"125""Mai""8000"},  
  8.         {"121""Sam""7000"}};  
  9.         String column[] = {"ID""NAME""SALARY"};  
  10.         JTable jt = new JTable(data, column);  
  11.         jt.setBounds(3040200300);  
  12.         JScrollPane sp = new JScrollPane(jt);  
  13.         jf.add(sp);  
  14.         jf.setSize(400400);  
  15.         jf.setVisible(true);  
  16.     }  
  17.     public static void main(String[] args) {  
  18.         new JTableExample();  
  19.     }  
  20. }  
  21.    
40

Output

41

Summary

Thus, we learnt that the JTable class displays the data on the two dimensional tables of the cells and also learnt how to use it in Java.