1

I have set a JTable to initialize at the beginning of the program, and I set it to a DefaultTableModel:

public DefaultTableModel usernameScraperTableModel = new DefaultTableModel();
private JTable usernameScraperTable;

I then initialize the table inside the constructor as below,

this.usernameScraperTable = new JTable(this.usernameScraperTableModel);
this.usernameScraperTableModel.addColumn("Username");

and then in my actionPerformed(ActionEvent) for my startButton, I run a method. If something is collected, it is supposed to add it to the table.

this.usernameScraperTableModel.addRow(new Object[] { user.getName() } );

It works somewhat. During run-time, the table is blank and doesn't show anything. I know this because in my Eclipse console it's working like it's supposed to. But after the method is done running, it then has the JTable update and all of the names are there.

I'm wondering how I can have my table update in real time inside of an ActionEvent of a button.


EDIT

Thanks for this. It still doesn't work though. I used WindowBuilder from the Eclipse website, and it's a JFrame. When I click start, the GUI kind of "freezes" (I can't click anything else, can't press the exit button, anything) until the method is done with

Community
  • 1
  • 1
Some Guy
  • 351
  • 1
  • 4
  • 20
  • possible duplicate of [JTable How to refresh table model after insert delete or update the data](http://stackoverflow.com/questions/3179136/jtable-how-to-refresh-table-model-after-insert-delete-or-update-the-data) – demongolem Apr 09 '14 at 20:11
  • `addRow` should do the trick. You need to provide a [MCVE](http://stackoverflow.com/help/mcve) for better help. – Paul Samsotha Apr 10 '14 at 00:15
  • It sounds like some process is blocking the Event Dispatching Process from been allowed to continue processing events (including paint events). Until the `actionPerformed` method exists, nothing can be updated. The question then is, what are you doing in you `actionPerformed` method? – MadProgrammer Apr 10 '14 at 01:27

1 Answers1

0

So I believe you want the method fireTableDataChanged() which is part of DefaultTableModel, which is usernameScraperTableModel in your case

demongolem
  • 9,474
  • 36
  • 90
  • 105
  • Thanks for this. It still doesn't work though. I used WindowBuilder from the Eclipse website, and it's a JFrame. When I click start, the GUI kind of "freezes" (I can't click anything else, can't press the exit button, anything) until the method is done with. – Some Guy Apr 09 '14 at 20:33
  • not all those notifiers are implemented in DefaultTableModel, usage of fireTableDataChanged() indicating concurency or EDT issue – mKorbel Apr 10 '14 at 06:46