Question

In a JDialog, when user clicks a JButton i want to execute 2 GUI actions in the EDT :

  1. Showing another small JDialog with a busy icon in it to tell the user "Please wait while the wrong process ends".
  2. Inserting a big number of records in a JTable.

When i try to execute both actions the "please wait" dialog blocks the inserting process, as expected.

As you see both actions must be done in EDT ... so is there a solution for this ?

Was it helpful?

Solution

No, both actions should not be executed in the EDT.

Your records should not be inserted in the JTable, but rather in its TableModel, triggering update events. This way, you can easily have the table updated while your dialog is shown.

Once the table model is updated, fire an event to ensure table is repainted, and it will work.

OTHER TIPS

The second thing does not need to be done in the EDT. Spawn off a thread to add the items to the JTable's model, but have that thread occasionally use SwingWorker.invokeLater() to fire off "fireTableDataChanged" events.

Most TableModels, for example the DefaultTableModel, invoke the fireXXX methods as soon as the model is updated so yes you want the updating of the model to be done on the EDT so the table gets repainted properly.

"Please wait while the wrong process ends".

Use an indeterminate JProgressBar

then you can update the model as required without it locking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top