File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTable - how can I repaint it with updated data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable - how can I repaint it with updated data" Watch "JTable - how can I repaint it with updated data" New topic
Author

JTable - how can I repaint it with updated data

B Walshe
Greenhorn

Joined: Jun 05, 2014
Posts: 2
Team,

Here's what I would like to happen:

  • Java/Swing dialog box appears on the user's screen
  • It allows the user to enter 2 values into labelled text fields (fname/sname)
  • They select a "Click Me" push button which I hope will write the data into the table

  • But the table does not get refreshed.

    If I minimise the dialog box and then open it again, the data still does not appear.

    The code I originally built using eclipse/WindowBuilder.
    I've cut it back and tried to isolate the issue.
    But I still cannot figure it out.

    I've added some diagnostic log messages to ensure that I am seeing the various events I think I need to see and have put code in the action callbacks etc.

    As I am a complete newbie at this sort of thing I am probably doing something silly - or forgetting to do something - or completely missing some significant point.
    Can someone help me out with this please?
    And thank you in advance.

    Rob Camick
    Ranch Hand

    Joined: Jun 13, 2009
    Posts: 2215
        
        7


    You are using the wrong DefaultTableModel constructor. You should create the model by only using the column names and 0 rows of data, since your data will be entered by the user and you don't know how many rows will be added. Read the DefaultTableModel API for the appropriate constructor to use




    To update data in the table, you need to update the data in the TableModel. You do this by using the addRow(...) method of the DefaultTableModel:



    The TableModel will then notify the table that the data has changed and the table will repaint itself automatically.
    B Walshe
    Greenhorn

    Joined: Jun 05, 2014
    Posts: 2
    That's it Rob!
    Got it straight away.
    Its that old TableModel stuff that I need to get my head around and the relationship between Tables and TableModels.

    Thank you for your help....now on to my next conundrum.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: JTable - how can I repaint it with updated data