I have made a java GUI program and have added a jList on that GUI so as to print output of the program on that jList by adding an item by calling
listBox.addElement(""); // where listBox is an instance of jList
But the problem is that the items are not being displayed at the time of addition. They are being shown when the program is about to finish.
Means, I am starting the program by clicking on a "Start" button and then the whole processing is done including the addition of items to the "listBox" but the items are shown on the jList when the program returns to the "actionPerformed()" method of the ActionListener of the "Start" button.
What can be done so as to show the items instantly when they are added to the list.
The above application is multithreaded. The main thread launch the GUI and then starts 10 threads and pass "listModel" (instance of DefaultListModel) of the jList to all the threads so that each thread can add items to the list by calling the "addElement("")" method on the "listModel"
In actual, listModel is an instance of a subclass (DefaultListModelSubClass) of DefaultListModel class. I have override the addElement() method to make it "synchronized" so that at one time only one thread can add an item to that.