Question

I want to highlight different sections of text when mouse is hovered over them. I'm currently using styleddocument with jTextPane. Can somebody please help me in defining style so that individual strings/paragraphs can be highlighted when mouseover occurs?

Thanks,

Was it helpful?

Solution

You can define a custom highlighter to show necessary colors. Add a MouseListener to the jTextPane. You can get mouse coordinates and use viewToModel() method of jTextPane to detect offset in the Document and process whether current section should be highlighted or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top