File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Filtering JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Filtering JTable" Watch "Filtering JTable" New topic
Author

Filtering JTable

Neil Barton
Greenhorn

Joined: Aug 24, 2011
Posts: 7
I want to filter a jtable using columns that are in a background array but not shown in the table. What I want to do is score each row, sort the array on the basis of the score and then display the result in a table.

I followed the sorting / filtering tutorial and can display the table and filter it using the columns showing in the table but when I try to write my own sorter using the columns in the array behind it I can't find a way that compiles.

Table
Partno, Description, Size

Array (of type product)
Partno, Description, Size, notes, longdescription, score

The user enters a string in a text field and that causes a loop through the array updating the score depending on whether it found the string and in which column. I then want to filter the table with only those that have a score > 0 showing and sort them by score.

I have come across a tutorial which says wrap the array in a model but when I do this I get an error saying "Type argument prodmgr.ProductModel is not within bounds of type variable M" I cannot understand this error message (where did it get M from?) and looking for this I can find no example that is similar.

I am using Netbeans (in case that changes anything), this show a rowsorter attribute in the table definition, would there be a way to put some custom code in here to make it sort on a field in the array?

All help appreciated,
Neil

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2584
    
    9

Hello

How are you getting your rows in your table model? Are you using the default table model or you write your own?

Not sure if this relates to the issue, is your Product class comparable?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Neil Barton
Greenhorn

Joined: Aug 24, 2011
Posts: 7
I was loading them into a DefaultTableModel and then setting the JTable model to that. I've now created a ProductModel class but I'm not sure it's helping. Since I did this I haven't been able to compile it. What I'm doing now is taking the filtertabledemo from the Java tutorial and building on that hoping that it will give me some way of tying it back to the array? I don't think it will do it. An alternative would be to have all of the columns in the table array but not show some of them; is that possible?

thanks for your help,
Neil
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2584
    
    9

What's your ProductModel looks like? Are you trying to implement your own table model using the ProductModel class?

Neil Barton
Greenhorn

Joined: Aug 24, 2011
Posts: 7
Great, thanks. That makes sense, I think that's where I'm going wrong. I'll have a play.

Thanks for putting me on the right track.

Regards,
Neil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filtering JTable