Hello frnds,
I am suffering with a problem. Please help me.

The problem is when i am displaying a list of items or say component in to view then the list got weird or we can say jumbled(one item above another) comes for a short moment(less than 1 sec). i tried to solve this but not able to solve.

I am using net.infonode.docking.View class to display view and using Jpanel. The list of items that need to display on panel is computed in separate thread. after computation i call method to request focus.

I tried the following solution.

Solution 1

1. Create the view.
2. Compute the list of item to display.
3. Request focus for view.

Solution 2
1. Create the panel.
2. Compute the item to display.
3. Create View.
4. Set panel in View as component.
5. Request focus for view.

Both solution is not working. the list of item is still weird for a moment. could you please help me

So i want to put some delay to display a view so that computation gets completed earlier and list is not weird.

Edited 6 Years Ago by pankajagar2002: n/a

As long as the list, a swing component, is getting updated by the EDT (the swing thread), not your other thread, everything should work fine. I'm not an expert but that has been my experience. Is that the case? You can test by calling this method in the method where you update the JList. That is just a guess, no guarantee that its good advice, but it is really quick to check.

Thanks for providing help.

but sir my list is computed in other thread. this thread take 10 - 15 sec to compute the list, meanwhile view come in display and as the thread(list compute) completed, it gets weird for a moment.

Thanks again

Thanks for providing help.

but sir my list is computed in other thread. this thread take 10 - 15 sec to compute the list, meanwhile view come in display and as the thread(list compute) completed, it gets weird for a moment.

Thanks again

Then you need to use a SwingWorker thread. Read this link. You might need to read about Swing & the event dispatch thread first (it is the article right before that one, the list is on the left). SwingWorker is perfectly suited for your task since the point is to execute long running tasks (such as your 10-15s one) in the background, then to update the Swing EDT on what it should do in response. There is also a full example which it links to at the top of the article.

Edited 6 Years Ago by BestJewSinceJC: n/a

This question has already been answered. Start a new discussion instead.