Scenario: I have been working on implementing a find and replace feature for a JavaFX table view. The goal is to automatically select the found text in the text field when it switches to edit mode.
However, the issue I am facing is that the text selection in the text field is only visible when the application has focus. As soon as the focus is lost, the text selection becomes invisible.
The Challenge: Is there a way to make the text selection in a text field visible even when the field does not have focus?
Approaches Tried:
I initially thought of using CSS to address this issue:
textField.setStyle("-fx-highlight-fill: lightgray");
While this changes the color of the highlighting, it did not achieve my desired outcome because:
- I wanted to retain the original color for the focused text field
- I aimed to change the color from "invisible" to "lightgray" only for the non-focused text field
What would be the correct approach to tackle this issue? Alternatively, is there a method to highlight text in a TableView without activating the TextField?
Thank you,
Ingo