Reputation: 1868
I am trying to programmatically set table in my Applet program. I tried the following code, it works fine. But, This is opening new window and then drawing the table. Can I have sample for drawing such table in the Applet view itself
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object rowData[][] = {
{ "Row1-Column1", "Row1-Column2", "Row1-Column3" },
{ "Row2-Column1", "Row2-Column2", "Row2-Column3" }
};
Object columnNames[] = { "Column One", "Column Two", "Column Three" };
JTable table = new JTable(rowData, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
Upvotes: 0
Views: 1247
Reputation: 42174
Instead of creating a JFrame and adding your JScrollPane to that, you should extend JApplet and simply add your JScrollPane to that.
Recommended reading: http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html
This is, of course, after taking into account the link Andrew Thompson already gave you.
Upvotes: 1