• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Filtering JTable

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Neil Barton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's your ProductModel looks like? Are you trying to implement your own table model using the ProductModel class?

 
Neil Barton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic