Table component in Java swing is created by the javax.swing.JTable class. This class is graphically representation of table. The graphical area is divided in to rows and columns and data are arranged into the cells.
Creating table
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import javax.swing.border.*;
class SwingDemo14
{
public static void main(String ar[])
{
JFrame f=new JFrame("Tool bar demo");
Object colNames[]={"Name","Phone","Address"};
Object rows[][]={ {"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"}
};
JTable tbl=new JTable(rows,colNames);
JScrollPane sp=new JScrollPane(tbl);
f.add(sp);
f.setBounds(100,100,400,300);
f.setVisible(true);
}
}
import javax.swing.event.*;
import java.awt.*;
import javax.swing.border.*;
class SwingDemo14
{
public static void main(String ar[])
{
JFrame f=new JFrame("Tool bar demo");
Object colNames[]={"Name","Phone","Address"};
Object rows[][]={ {"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"},
{"ABC","345345","T-&*6,kdjhfkj"}
};
JTable tbl=new JTable(rows,colNames);
JScrollPane sp=new JScrollPane(tbl);
f.add(sp);
f.setBounds(100,100,400,300);
f.setVisible(true);
}
}
Comments