JTable class in java

JTable class

JTable class is useful to create a table. A table represents several rows and columns of data.

Constructors

  • JTable()
  • JTable(Object[][] rows, Object[] columns)

Methods

  • int getRowCount();
  • int getColumnCount();
  • int getRowHeight();
  • int getColumnHeight();
  • int getSelectedRow();
  • int getSelectedColumn();
Example
import javax.swing.*;
public class test
{
JFrame f;
test()
{
f=new JFrame();
String data[][]={ {“1″,”John”,”10000″}, {“2″,”Adam”,”20000″}, {“3″,”Sandy”,”30000″}};
String column[]={“ID”,”NAME”,”SALARY”};
JTable jt=new JTable(data,column);
jt.setBounds(30,30,200,300);
JScrollPane sp=new JScrollPane(jt);
f.add(sp);
f.setSize(300,400);
f.setVisible(true);
}
public static void main(String[] args)
{
new test();
}
}

Output:

Untitled

Leave a Reply

Your email address will not be published. Required fields are marked *