01: package Language;
02:
03: import java.util.*;
04: import javax.swing.table.*;
05: import javax.swing.*;
06: import java.awt.*;
07:
08: public class SearchStringTableCellRenderer extends
09: DefaultTableCellRenderer {
10:
11: public SearchStringTableCellRenderer() {
12: } // Constructor
13:
14: String searchString = "";
15:
16: public void setSearchstring(String s) {
17: searchString = s.toUpperCase();
18: }
19:
20: public Component getTableCellRendererComponent(JTable table,
21: Object value, boolean isSelected, boolean hasFocus,
22: int row, int column) {
23: int fs = UIManager.getFont("Label.font").getSize();
24: setBorder(BorderFactory.createEmptyBorder(fs / 10, fs / 2,
25: fs / 10, fs / 4));
26: String strValue = (String) value;
27:
28: setIcon(null);
29: setText((value != null) ? value.toString() : "");
30: setHorizontalAlignment(JLabel.LEFT);
31:
32: if (isSelected) {
33: super .setForeground(table.getSelectionForeground());
34: super .setBackground(table.getSelectionBackground());
35: } else {
36: if (row % 2 == 0) {
37: setBackground(new Color(0, 0, 117, 10));
38: } else {
39: setBackground(Color.white);
40: }
41: }
42:
43: if (searchString.length() > 0
44: && strValue.toUpperCase().indexOf(searchString) != -1) {
45: setBackground(new Color(220, 220, 70, 150));
46: }
47:
48: return (this );
49: }
50:
51: } // DefaultTableCellRenderer
|