Results 1 to 4 of 4

Thread: Updating JTable

  1. #1
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default 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);

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    > 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 );

  4. #4
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by camickr View Post
    > 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 );
    thanks so much
    you my friend, are a life saver

Similar Threads

  1. Problem with updating empty JTable
    By byubi in forum AWT / Swing
    Replies: 1
    Last Post: 05-15-2010, 08:31 AM
  2. Updating the existing JTable !
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 04-07-2010, 08:38 PM
  3. Problem with updating JTable
    By kwaspl in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 10:41 PM
  4. Replies: 0
    Last Post: 08-29-2008, 12:49 PM
  5. Updating database table from JTable
    By yesjava in forum New To Java
    Replies: 1
    Last Post: 08-16-2008, 10:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •