Hey try my code also...
<pre>
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class Test12 extends JFrame implements ActionListener{
JButton add;
int i=1;
Vector rows=new Vector();
Vector cols=new Vector();
JTable table;
DefaultTableModel model;
public Test12() {
super("JTable");
add=new JButton("Add");
add.addActionListener(this);
JPanel panel1=new JPanel();
panel1.add(add);
cols.add("Comp Name");
model=new DefaultTableModel(rows,cols);
table=new JTable(model);
JScrollPane tableScrollPane=new JScrollPane(table);
Container content=getContentPane();
content.setLayout(new GridLayout(2,1));
content.add(panel1);
content.add(tableScrollPane);
Vector v=new Vector();
setSize(300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
JButton actionButton=(JButton)ae.getSource();
if(actionButton==add) {
Vector temp=new Vector();
temp.add("C-"+ i++);
model.addRow(temp);
}
}
public static void main(String args[]) {
new Test12().addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
</pre>
Bhupendra Mahajan [This message has been edited by Mahajan Bhupendra (edited December 28, 2001).]