JTable class (Swing Tutorial)
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
public class MyTable {
JFrame f;
MyTable(){
f=new JFrame();
String data[][]={ {"101","Amit","670000"},
{"102","Jai","780000"},
{"101","Sachin","700000"}};
String column[]={"ID","NAME","SALARY"};
JTable jt=new JTable(data,column);
jt.setBounds(30,40,200,300);
JScrollPane sp=new JScrollPane(jt);
f.add(sp);
f.setSize(300,400);
// f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new MyTable();
}
}
No comments:
Post a Comment