Is it possible to highlight a substring inside of a TableView Cell in JavaFX 2 by giving the substring another color for example? If yes, how is this achievable?
Glad for any advice!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One possible solution for Java7. Use a cell factory for your cell. From the factory return a TextField. Set the TextField to not editable. Use the TextField’s methods to select the text you want to highlight (might need a Platform.runLater method to do that and the field might need to be focused to allow to select the text). Once the selection is complete (and really displayed), Disable mouse input and focus traversion on the TextField so that the user can’t change the selection maybe also in a Platform.runLater.
For Java8, you can do the similar thing, but instead of a TextField, use a TextFlow and style the subtext in the text flow using css or Java APIs.
If you just want to highlight all of the text in the cell, rather than some portion of it, then you can just use a standard Label plus css styling. Another solution for partial text highlighting is to use a FlowPane with multiple labels inside and different styling for each.