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,

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top