I am creating a table at run time after fetching the result from the database. The flow of my application is like this.
- Initializing a empty JScrollPane();
JScrollPane tableScroll = new JScrollPane(); - Fetching result from the database;
- Updating result to JTable and adding JTable to JScrollPane using following method:
Code:
private void setResultTable(Vector documents, Vector header) {
TableModel model = new DefaultTableModel(documents, header);
documentTable.setModel(model);
tableScroll.add(documentTable);
tableScroll.repaint();
}
my problem is that after calling setResultTable the result are not appearing in the table. Please help me with that. Thanks in advance !!!
You appear to be adding the JTable directly to the JScrollPane. If so this isn’t correct and you’ll want to change this so that you’re actually adding the table to the scroll pane’s viewport:
There is no need to repaint the JScrollPane after doing this.
For example:
If this doesn’t help, you’ll want to also tell us exactly what happens, what you see, and if possible supply us with a small compilable runnable program that demonstrates your problem, an SSCCE