-1

I'm working with Java Netbeans and I've a JTable which contains many values and I'm doing a search. This is my code - it works well.

private void txtRechEHSKeyReleased(java.awt.event.KeyEvent evt) {
    String re=comboSearchByEHS.getSelectedItem().toString();
    String sql = "select * from equipement where "+re+" like ? ";
    try{
         ps = con.prepareStatement(sql);
        ps.setString(1, txtRechEHS.getText()+"%");
       SearchEHS();
    }catch (Exception e){
        JOptionPane.showMessageDialog(null,e);
    } 
}  

I want that when it searches and gets the result, that the found row the user is looking for gets colorized. How can I do that?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Samer
  • 126
  • 1
  • 9
  • 2
    Why not implement a [`RowSorter`](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting) (which is also a **filter**)? Nothing highlights the found record(s) as good as making them the only ones to appear! See also this [working example](http://stackoverflow.com/a/28621618/418556) that filters a font list. – Andrew Thompson Mar 03 '15 at 21:14

1 Answers1

0

You need TableCellRenderer for that purpose or (in some cases) DefaultTableCellRenderer

*upd

See SO Changing Swing JTable Cell Colors, SO Change background color of one cell in JTable [duplicate]

Community
  • 1
  • 1
Sergey Mashkov
  • 4,630
  • 1
  • 27
  • 24