Hi,
I wrote the followiing code for a Jtable:
public class simpletabletest extends JPanel{
public simpletabletest() {
String[][] data = { {"...", "...", "...", "..."},
{"...", "...", "...", "..."},
{"...", "...", "...", "..."}};
String[] Columns = {"Name", "LastName", "Phone", "MobilePhone"};
//DefaultTableModel model = new DefaultTableModel(data, Columns);
JTable table = new JTable(data, headers);
table.setPreferredScrollableViewportSize(new Dimension(500,60));
table.setFillsViewportHeight(true);
JScrollPane jps = new JScrollPane(table);
add(jps);
}
}
If i have a main method and like bellow the table t appears to the JFrame
public static void main(String[] args) {
JFrame jf = new JFrame();
simpletabletest t = new simpletabletest();
jf.setSize(600, 500);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(t);
}
I use NetBeans and i make a newJframe form from design. After that in formWindowOpened event i write
simpletabletest t = new simpletabletest();
add(t);
but the table doesn't appears to the JFrame.
Can someone help me with this?
thanks in advance.