71 |
} |
} |
72 |
|
|
73 |
/** |
/** |
74 |
|
* Stores the color set by setForeground(). |
75 |
|
*/ |
76 |
|
Color foreground; |
77 |
|
|
78 |
|
/** |
79 |
|
* Stores the color set by setBackground(). |
80 |
|
*/ |
81 |
|
Color background; |
82 |
|
|
83 |
|
/** |
84 |
* Creates a default table cell renderer with an empty border. |
* Creates a default table cell renderer with an empty border. |
85 |
*/ |
*/ |
86 |
public DefaultTableCellRenderer() |
public DefaultTableCellRenderer() |
96 |
public void setForeground(Color c) |
public void setForeground(Color c) |
97 |
{ |
{ |
98 |
super.setForeground(c); |
super.setForeground(c); |
99 |
|
foreground = c; |
100 |
} |
} |
101 |
|
|
102 |
/** |
/** |
107 |
public void setBackground(Color c) |
public void setBackground(Color c) |
108 |
{ |
{ |
109 |
super.setBackground(c); |
super.setBackground(c); |
110 |
|
background = c; |
111 |
} |
} |
112 |
|
|
113 |
/** |
/** |
119 |
public void updateUI() |
public void updateUI() |
120 |
{ |
{ |
121 |
super.updateUI(); |
super.updateUI(); |
122 |
|
background = null; |
123 |
|
foreground = null; |
124 |
} |
} |
125 |
|
|
126 |
/** |
/** |
154 |
|
|
155 |
if (isSelected) |
if (isSelected) |
156 |
{ |
{ |
157 |
setBackground(table.getSelectionBackground()); |
super.setBackground(table.getSelectionBackground()); |
158 |
setForeground(table.getSelectionForeground()); |
super.setForeground(table.getSelectionForeground()); |
159 |
} |
} |
160 |
else |
else |
161 |
{ |
{ |
162 |
setBackground(table.getBackground()); |
if (background != null) |
163 |
setForeground(table.getForeground()); |
super.setBackground(background); |
164 |
|
else |
165 |
|
super.setBackground(table.getBackground()); |
166 |
|
if (foreground != null) |
167 |
|
super.setForeground(foreground); |
168 |
|
else |
169 |
|
super.setForeground(table.getForeground()); |
170 |
} |
} |
171 |
|
|
172 |
if (hasFocus) |
if (hasFocus) |
173 |
{ |
{ |
|
setBackground(table.getBackground()); |
|
174 |
setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); |
setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); |
175 |
|
if (table.isCellEditable(row, column)) |
176 |
|
{ |
177 |
|
super.setBackground(UIManager.getColor("Table.focusCellBackground")); |
178 |
|
super.setForeground(UIManager.getColor("Table.focusCellForeground")); |
179 |
|
} |
180 |
} |
} |
181 |
else |
else |
182 |
setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
183 |
|
|
|
setEnabled(table.isEnabled()); |
|
184 |
setFont(table.getFont()); |
setFont(table.getFont()); |
185 |
|
|
186 |
|
// If the current background is equal to the table's background, then we |
187 |
|
// can avoid filling the background by setting the renderer opaque. |
188 |
|
Color back = getBackground(); |
189 |
|
setOpaque(back != null && back.equals(table.getBackground())); |
190 |
|
|
191 |
return this; |
return this; |
192 |
} |
} |
193 |
|
|