I’m writing an application which parses XML files (continuously) and show the data in a GUI (Swing). The ParseThread is in the CoreProject, and the GUI is in the GUIProject.
The start of the ParseThread is connected to a JCheckBoxMenuItem with an ItemListener. The value of setSelected() is set directly after adding to the Menu. At this time the GUI does not contain the Component which the ParseThread needs to show the parsed Data.
My Solution is, that the ParseThread should wait until the GUI is build completely.
I thought of something like an EventQueue but I have no Idea how to code one.
you have got issue with Concurency in Swing, your hard and long running task should be moved to the Background task, for Swing there are two possibilities
(easy & simple) use
Runnable#Thread, output to Swing GUI must be wrapped intoinvokeLater(), including thread safe methods as aresetText,appende.i.use SwingWorker
EDIT
please to check my visulaizations for Runnable#Thread this is the same thing as you connect server, parse long file e.i.,
create GUI,
show GUI,
some
(Swing / Util) Timeroruser actionto invoke code that is/are redirected out ofSwing EventDispatchThread, for this reason there areRunnable#ThreadorSwingWorkerI’m suggest two easiest of possible ways