aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Count items in JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Count items in JList" Watch "Count items in JList" New topic
Author

Count items in JList

yesaya handoyo
Greenhorn

Joined: Aug 31, 2008
Posts: 25
Hi all,i want to ask how to count items in the JList..Thanks a lot..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

The JList is not aware of the actual data.
As with all components following MVC, there is a model associated with the JList which holds the data.

So what you need to do is get the model from the JList and then query it for the item count.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
yesaya handoyo
Greenhorn

Joined: Aug 31, 2008
Posts: 25
I get from the forums.sun.com like this..
int size = list.getModel().getSize();
What do you think??Thanks a lot..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Originally posted by yesaya handoyo:
I get from the forums.sun.com like this..
int size = list.getModel().getSize();
What do you think??Thanks a lot..


The real question is what do you think?
Is this different from what I said?

Did you try it out?
Did you get any results?
Are they correct?

Also please do take out time to read this important information
yesaya handoyo
Greenhorn

Joined: Aug 31, 2008
Posts: 25
I've not tried it out..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

What do you get if you do?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Count items in JList
 
Similar Threads
Unable to delete a list entry at runtime
How we can restrict the no of selections in a JList
Working on a JList and giving it more options?
Change the font in a JList
Which Swing component to use ?