• 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

search function in JTable

 
Ranch Hand
Posts: 201
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best ranchers!

I am trying to write a search function for a JTable in one of my projects. Im struggling really hard with this. Can anyone help me to see what i am missing?
Or maybe point me in the right direction. I want to loop through all columns in my JTable and match the data in theese with values from a JTextField.

What i have tried so far -  however this attempt was unsuccessful - is the following lines of code. The goal is to highlight the row with the columns in my JTable
that contains the value of the JTextField everytime after the user has clicked a search button. My approach to this problem maybe was totally wrong. I don't
wan't to use the TablrRowSorter or RowFilter classes as a search function just a simple highlight of the row that contains the value that was entered into
the JTextField.

The code below doesn't find the row desired row it only highlight some row two or more steps above it randomly. Maybe i should look into cell renderers
a little deeper but than again i need help with this one. please.



//Robert
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API Javadoc

public void setRowSelectionInterval(int index0,
                                   int index1)
Selects the rows from index0 to index1, inclusive.


This sets the current selection range

However, there is another method

addRowSelectionInterval
public void addRowSelectionInterval(int index0,
                                   int index1)
Adds the rows from index0 to index1, inclusive, to the current selection.


This adds to the existing selection range.

Try using the second method
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic