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
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: 10523
    
    9

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: 10523
    
    9

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: 19761
    
  20

What do you get if you do?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Count items in JList