Get current instance of Runnable

1k views Asked by At

I'm making an application that allows users to view task lists stored in different databases. So what happens is that, I have a list of the names of browsable databases (stored as a text file). Program loads the first database in that list and displays contents. Then from a menu, I allow users to select another database in the list. (Kind of like, I want to view the tasks for Andy, and now Bob, and now Carl...).

Problem is, I don't know how to update the UI so that the contents of the new database is displayed. It's trivial to remove the tasks currently listed, read from the DB, and then repopulate. But I can't get to this code (from my Singleton database driver) because I would need access to the instance of my Runnable which was loaded to the EventQueue (all my JComponents are private, as with all tutorials I've so far encountered). I'm looking at the get/peek methods in EventQueue but they don't seem to be what I need since they return AWTEvents and I don't see any relation between AWTEvent and Runnable other than java.lang.Object.

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

Thanks in advance for any guidance.

2

There are 2 answers

1
Hovercraft Full Of Eels On BEST ANSWER

I suspect that you are going about this wrong. What you want to do is change databases from within a control class (using MVC nomenclature). For instance, say you load the available databases into a JList, then in the control for this component, say a ListSelectionListener, you execute a SwingWorker that loads the new database and then displays the results in the GUI either via its publish/process pair of methods or in the done method. The database code (the model) should know nothing about the view or GUI portion of your code (the Runnable as you call it).

0
mKorbel On

there is a good tutorial about Concurency in Swing and nobody can't tell about that, that is out-dated

you have two choises

1) Runnable#Thread, but all output to the GUI must be wrapped into invokeLater(), more details in the tutorial about Concurency in Swing

2) or by using SwingWorker