Results 1 to 4 of 4
Thread: Updating JTable
- 03-30-2011, 10:08 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 67
- Rep Power
- 0
Updating JTable
Hello
I am having trouble updating my JTable.
I use a method to retrieve data in the form of a TableModel.
I use that TableModel in the JTable constructor.
But I can't figure out how to refresh the JTable when I change the data in the TableModel.
Here is my code.
Any help would be greatly appreciated
Thanks.
Java Code:DatabaseManager dbman = new DatabaseManager(); TableModel recordTableModel = dbman.getRecordTable(); recordTable = new JTable(recordTableModel) { public boolean isCellEditable(int row, int column) { return false; }; }; JScrollPane tableScrollPane = new JScrollPane(recordTable); tableScrollPane.setSize(200, 200); JPanel panel = new JPanel(); panel.add(tableScrollPane); add(panel);
-
Check this tutorial on listening to data changes in JTable:
How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
- 03-31-2011, 12:31 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
> But I can't figure out how to refresh the JTable when I change the data in the TableModel.
There is no need to create any new components. You just update the existing table by using:
Java Code:table.setModel( recordTableModel );
- 03-31-2011, 09:59 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 67
- Rep Power
- 0
Similar Threads
-
Problem with updating empty JTable
By byubi in forum AWT / SwingReplies: 1Last Post: 05-15-2010, 08:31 AM -
Updating the existing JTable !
By Stephen Douglas in forum New To JavaReplies: 2Last Post: 04-07-2010, 08:38 PM -
Problem with updating JTable
By kwaspl in forum New To JavaReplies: 2Last Post: 12-20-2009, 10:41 PM -
Is there a way for updating JTree and JTable with a same model?
By Melki in forum AWT / SwingReplies: 0Last Post: 08-29-2008, 12:49 PM -
Updating database table from JTable
By yesjava in forum New To JavaReplies: 1Last Post: 08-16-2008, 10:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks