Skip to content

Commit f319c8f

Browse files
ctruedenclaude
andcommitted
Use foreground text color for search bar text
In case the Look & Feel is in dark mode. :-) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent ad44aba commit f319c8f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/main/java/org/scijava/ui/swing/search/SwingSearchBar.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@
105105
public class SwingSearchBar extends JTextField {
106106

107107
private static final String DEFAULT_MESSAGE = "Click here to search";
108-
private static final Color ACTIVE_FONT_COLOR = new Color(0, 0, 0);
108+
private static final Color DEFAULT_ACTIVE_FONT_COLOR = new Color(0, 0, 0);
109+
/** Text color while typing; follows the look and feel (e.g., dark themes). */
110+
private static Color activeFontColor() {
111+
final Color c = UIManager.getColor("TextField.foreground");
112+
return c == null ? DEFAULT_ACTIVE_FONT_COLOR : c;
113+
}
114+
109115
private static final Color INACTIVE_FONT_COLOR = new Color(150, 150, 150);
110116
private static final Color SELECTED_RESULT_COLOR = new Color(186, 218, 255);
111117
private static final String CONTEXT_COLOR = "#8C745E";
@@ -170,7 +176,7 @@ public void changedUpdate(final DocumentEvent e) {
170176
@Override
171177
public void focusGained(final FocusEvent e) {
172178
if (DEFAULT_MESSAGE.equals(getText())) setText("");
173-
setForeground(ACTIVE_FONT_COLOR);
179+
setForeground(activeFontColor());
174180
}
175181

176182
@Override

0 commit comments

Comments
 (0)