Get Current Runnable Instance

I am creating an application that allows users to view lists of tasks stored in different databases. So what happens is that I have a list of names of databases available for viewing (stored as a text file). The program loads the first database into this list and displays the contents. Then from the menu, I allow users to select another database in the list. (It seems like, I want to see the tasks for Andy, and now Bob, and now Karl ...).

The problem is that I do not know how to update the interface so that the contents of the new database are displayed. It is trivial to delete the tasks currently listed, read from the database, and then repopulate. But I can’t get to this code (from my Singleton database driver), because I need access to the instance of my Runnable that was loaded in the EventQueue (all my JComponents are private, as with all the tutorials that I still have met). I look at the get / peek methods in EventQueue, but they don't seem to be what I need as they return AWTEvents, and I don't see any connection between AWTEvent and Runnable except for java.lang.Object.

So, is it possible to get the current runnable? How?

Thanks in advance for any recommendations.

+1
source share
2 answers

I suspect you are going about this. You want to change the databases from the management class (using the MVC nomenclature). For example, let's say you load available databases into a JList, and then into the control for that component, say ListSelectionListener, you run SwingWorker, which loads the new database and then displays the results in the GUI or through its publish / process method pair or in a done method. The database code (model) should not know anything about the part of the view or graphical interface of your code (Runnable, as you call it).

+2
source

there is a good tutorial about Concurency in Swing , and no one can say about it, i.e. outdated

you have two choices

1) Runnable#Thread , but all output in the GUI should be wrapped in invokeLater() , in more detail in the Concurency in Swing manual

2) or using SwingWorker

+3
source

Source: https://habr.com/ru/post/914918/


All Articles