How can I change the color of the UI components when some other thread is running?

I have some kind of build game (yes this is a concession from university) that I need to go through some matrix representing a two-state board (boolean [] []). This tip can be thought of as a GUI that builds with JLabels in two colors.

The idea is to have some kind of background process that forces each cell to update the matrix according to certain rules. According to these rules, I need to change the value of the matrix cell in the interface side.

Currently I have created a separate thread for the process that walks through the matrix and validates the correctness that I got, and another thread that is responsible for making changes to the UI.

So the first thread works well while the second does nothing.

So my question is, what's the best way to change Swing UI while some other process is running in the background?

What I have done so far:

this.golThread = new Thread(golr);
golr.setRunningMode(true);
golThread.start();

this.uiThread = new Thread(ui);
ui.setRunningMode(true);
uiThread.start();       

      

And I also tried using: SwingUtilities.invokeLater(uiThread);

+3


source to share





All Articles