Component not revalidating when called from listener of messaging infrastructure

Answered

I am trying to develop an Intellij IDEA plugin with Swing and I am using the messaging infrastructure: https://plugins.jetbrains.com/docs/intellij/messaging-infrastructure.html?from=jetbrains.org

I have a method to update my table: (MyDataTable class)

```java
public void updateComponentData(ArrayList<MyData> someData) {
int rowIndex = 0;
tableModel = new MyCustomModel();
tableModel.setDataLength(errors.size());
for (MyData data : someData) {
tableModel.setValueAt(data.getMyProp(), rowIndex, tableModel.myColIndex);
// add more cell ....
rowIndex++;
}

table.setModel(tableModel);
tableModel.fireTableDataChanged();
table.revalidate();
}

```

Then I call this method from another class and revalidate:

```
myDataTable.updateComponentData(latestErrors);
mainPanel.revalidate();

```

Now this method works perfectly if I call it from a "normal" method,
however it does not refresh the UI if I call it from the subscriber listener.

```
public class MyMainClass implements MyDataTopic {
@Override
public void afterAction(ArrayList<MyData> someData) {
myDataTable.updateComponentData(latestErrors);
mainPanel.revalidate();
}
}

```
The data arrives correctly, but it does nothing.

Might be a race condition or something?
Any idea? Thanks.

0
3 comments

UI Code must be run on EDT thread, not any other thread used from Messaging. See also https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html as reference.

0

Hi, i think i am having a similar issue here - i have a component value change listener. When it is activated, it will modify the UI component:

aPanel.removeAll();

aPanel.add(aTabbedPane);

aPanel.revalidate();

 

however, the content does not seem refreshed. Yann Cebron noted your comment above. Do you mean the listener action is not on EDT? Any way i can force it to EDT? 

The strange thing is that, this code is running perfect well with previous version of IDEA (2019.1.4 when this plugin was created), but no longer working with newer version now. 

0

Please sign in to leave a comment.