Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java coloring characters GUI

I am making a GUI dictionary program and have an input of letters that need to be highlighted in each words that is display. I was wondering how to do this, it doesn't seem very hard to color my entire JTextArea, but coloring only certain characters seems to be a little more difficult. I have read about JTextPane where I can use styled fonts, but even that doesn't seem straightforward. I need to parse every dictionary word's character and then change that characters color.

like image 583
user1104154 Avatar asked Feb 22 '26 15:02

user1104154


1 Answers

Yes, you'd want to use JEditorPane or JTextPane to do this sort of thing. You can either use styles, as you've seen, or you could create the contents as HTML and display that, which would be a lot simpler, if less flexible.

The relevant section of the Java Tutorial starts here.

like image 162
Ernest Friedman-Hill Avatar answered Feb 25 '26 05:02

Ernest Friedman-Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!