• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

How to reduce JList loading time

I have created a class MyListModel that extended AbstractListModel to create my own list model for JList. I have added list selection listener and mouse listener.

If i try to load large number of data say more than 8000 or 9000, it gets long time to load.

I have checked it found , the override method "public Object getElementAt(int index)" in Mylistmodel  gets called more than twice or thrice for all rows returned by the
override method " public int getSize()" , and at last it is called for number of visible rows. Due to this loading of list takes large time for large number of data.

Is it possible to reduce this number of calls to only one , or how can i reduce the loading time. Its very urgent please provide exact solution,
0
Computer07
Asked:
Computer07
  • 7
  • 5
  • 4
5 Solutions
 
for_yanCommented:
What it is that you display in the Jlist?
Are those just strings?
0
 
for_yanCommented:
Would not it be faster if you just construct it as JList(Vector)
Probably should be the same and for long vector will still take long time, but
I'd make a try
0
 
for_yanCommented:
I would think about redesigning the application in this situation - even
if it loads OK, then slection of the item out fof 9000 for the user is not a very
nice experience either. Perhpas you can rethink something in the logic of the application to
reduce the number of selections.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
for_yanCommented:
0
 
for_yanCommented:
Look at the bottom of the last link

http://stackoverflow.com/questions/853168/is-there-a-lazy-loading-implementation-of-jlist 

seems to address something you mentioned

Stilll, I'd reduce the total number  changing the design
0
 
objectsCommented:
sounds like the problem is in your model. make sure it is optimised to retrieve elements efficiently.
0
 
Computer07Author Commented:
Hi yan i have implemented my own model From ListModel and now its working fine. But for the first time it still takes long time. The link you have provided, i think i need to implement myList.setPrototypeCellValue(long value).  
 " But i am using my own renderer , it displays image and a text below the image  in each cell".
I have set the renderer size with myRenderer.setPreferredSize(new Dimension(150, 150));

Could you please tell me how to set setPrototypeCellValue(long value) in my renderer that contains image and text.
0
 
objectsCommented:
prototype cell value is not going to make any difference

sounds ike your problem is with the actual loading. make sure you are loading the model *before* you set it as your lists model
0
 
Computer07Author Commented:

public class MyListModel extends AbstractListModel{
      private int numberofrows;
      public MyListModel() {
            numberofrows = 0;
      }

      @Override
      public int getSize() {
            return mNumberOfFiles;
      }

      @Override
      public Object getElementAt(int index) {
            System.out.println("---getelement at::"+index);
            return data;
      }
      
      public void setNumberOfFiles(int totalfiles){
            numberofrows = totalfiles;
            fireContentsChanged(this, 0, getSize());
      }

}

This was the model that i was using .

i have implemented my own model From " ListModel " instead of  extending " AbstractListModel " and now its working fine . But for the first time it takes long it think its for calculating the cell size.

i think i need to implement myList.setPrototypeCellValue(long value).  
 " But i am using my own renderer , it displays image and a text below the image  in each cell".
I have set the renderer size with myRenderer.setPreferredSize(new Dimension(150, 150));

Could you please tell me how to set setPrototypeCellValue(long value) in my renderer that contains image and text.
0
 
objectsCommented:
list.setPrototypeCellValue("some sample data");
0
 
objectsCommented:
and you shouldn't need to set the prefrred size of the renderer
0
 
for_yanCommented:

Wouldn't it be faster if  set  setFixedCellWidth and setFixedCellHeight ?
0
 
objectsCommented:
> i have implemented my own model From " ListModel " instead of  extending " AbstractListModel "

thats rarely a good idea. you'll get problems with your list not updating correctly
0
 
Computer07Author Commented:

>>>>>
list.setPrototypeCellValue("some sample data");
setFixedCellWidth and setFixedCellHeight

Using this makes a lot of difference, and the size of each each cell is not calculated separately for each cell and really increase the performance.
0
 
Computer07Author Commented:
> i have implemented my own model From " ListModel " instead of  extending " AbstractListModel "

>>thats rarely a good idea. you'll get problems with your list not updating correctly

Was really creating problem during updates. so back to AbstractLsitModel with  setPrototypeCellValue("some sample data");
setFixedCellWidth and setFixedCellHeight
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now