Monday, 13 April 2015

JTable class

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



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

25. }  

No comments:

Post a Comment

Access attributes in component

NOTE: To access an attribute in a  component , use expressions as  {! v.<Attribute Name>} . ----------------------------------------...