• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList painting

 
Jacob Whitten
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have my JList get filled up using the Default model and this works fine . i have it in a swing worker with a short pause via the thread sleep method so it gives the impression to fill up incrementally but if i only give it rest for 100 then when the list gets longer and the scroll bar appears the whole list disappears for split second and comes back doing this a few times as list fills up. if i put it to rest of 1000 this does not happen but it is not as effective. the list is filled up with icons and file name from a search of specicific files on the hard drive.
i used the repaint after each sleep and still it flashes off and on the list i mean.

i don't want pause of 1000 second cause it is a bit slow. i mean java is fast but to the user 1 second is slow between each item coming into list.

thanks for your any help
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jacob Whitten:

i used the repaint after each sleep and still it flashes off and on the list i mean.


Try using the add method in the DefaultListModel which will internally call the paint. You dont really need to call the paint/repaint/revalidate explicity to update the list data.

Regarding the flasing problem, looks like a threading problem to me. Are you using SwingUtilities.invokeLater() ?
 
Jacob Whitten
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply to questions

i have the functions in a swing worker. i always use EventQueue.invokeLater for any gui related task even setting text so no i don't believe this is the problem. i will try to have the list filled using added and then then rplace it with the model
as i said up in the post when i set the sleep method to 1 second the flashing off and on of the list doesn't occurr. i can have the model fill up and then add it all in one shot at the end but it gives the impression nothing is happening and it is alot of work to coordinate a progressbar with an unknown quantity of items
 
Jacob Whitten
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:


What is this pathList? Is it the instance of the JList? If yes, what is the model?
I tried the following to try and simulate your situation. Works fine for me without any flicker. Please note I am updating only the listModel and not calling any repaint explicitly.


I read somewhere that the human eye cannot discern movements less than 1/16th of a second. Thats the reason the sleep is for 6 milliseconds. Gives the illusion of animation nicely.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the multiple posts and editing. Messed it up while trying to get the formatting straight!
 
Jacob Whitten
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pathList is LinkedList<String>(); for the file path the JList holds just the filenames so there are two list one in the backgroud for file paths obviously so the user can access the file

by the way i am using one of the synthetica Black Moon look and feel and this is not the problem i tried using the java default ocean them and it still does what i explained up above but only if i set the sleep to 100 or 150 as you have it in the above code
i don.t really need to have the list fill up incrementally cause the model and list itslef work fine it is filling it this way that is faulty but visually it is more intersting than to suddenly have the whole list pop into view
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!