I have here the code when a button is clicked. It is supposed to add a JTable
in the JPanel regularPanel
. The problem is that it doesn't show in the panel.
I added the panel in the frame via clicking the panel component.
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"Kathy", "Smith",
"Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe",
"Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black",
"Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White",
"Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown",
"Pool", new Integer(10), new Boolean(false)}
};
JTable table = new JTable(data,columnNames);
table.setBounds(100, 100, 100, 80);
JScrollPane tableContainer = new JScrollPane(table);
regularPanel.add(tableContainer);
What should I do to view that table in the panel?