All for Joomla All for Webmasters

JTable class

The JTable class is used to display the data on two dimensional tables of cells.

Commonly used Constructors of JTable class:

  • JTable(): creates a table with empty cells.
  • JTable(Object[][] rows, Object[] columns): creates a table with the specified data.

Example of JTable class:

  1. import javax.swing.*;
  2. public class MyTable {
  3.     JFrame f;
  4. MyTable(){
  5.     f=new JFrame();
  6.     String data[][]={ {“101”,“Amit”,“670000”},
  7.               {“102”,“Jai”,“780000”},
  8.                           {“101”,“Sachin”,“700000”}};
  9.     String column[]={“ID”,“NAME”,“SALARY”};
  10.     JTable jt=new JTable(data,column);
  11.     jt.setBounds(30,40,200,300);
  12.     JScrollPane sp=new JScrollPane(jt);
  13.     f.add(sp);
  14.     f.setSize(300,400);
  15. //  f.setLayout(null);
  16.     f.setVisible(true);
  17. }
  18. public static void main(String[] args) {
  19.     new MyTable();
  20. }
  21. }
PinIt
submit to reddit

Leave a Reply

Top