- #1
zak100
- 462
- 11
Hi,
I am trying to add data in a table. I am not getting any error but table is not vi
Some body please guide me why i can't see the table data?
Zulfi.
I am trying to add data in a table. I am not getting any error but table is not vi
Java:
import javax.swing.*;
import java.util.*;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class TableEg{
JFrame frame = new JFrame("Table Eg1");
JPanel panel = new JPanel();
JTable table = new JTable();
DefaultTableModel model = new DefaultTableModel( );
JScrollPane scrollPane = new JScrollPane(table);
TableEg() {
Vector<String> rowOne = new Vector<String>();
rowOne.addElement("Row1-Column1");
rowOne.addElement("Row1-Column2");
rowOne.addElement("Row1-Column3");
model.addRow(rowOne);
Vector<String> rowTwo = new Vector<String>();
rowTwo.addElement("Row2-Column1");
rowTwo.addElement("Row2-Column2");
rowTwo.addElement("Row2-Column3");
model.addRow(rowTwo);
table.setModel(model);
frame.setSize(500,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
panel.add(table);
panel.add(scrollPane);
frame.setVisible(true);
}
public static void main(String args[]){
new TableEg();
}
}
Zulfi.