Pregunta

I am working on jtextpane that have text with different foreground colors. I want to set tooltip on different colored text. Can anyone tell me how should I get the color of particular postion or location in jtextpane. I have set different foreground color on text by StyleConstants.setForeground method on jtextpane. I have found the position of mouse by this method.

 int ind=jTextPane2.viewToModel(evt.getPoint());

Now I want to have the foreground color of this ind variable. This ind is particular point on which the mouse is. Now Can anyone tell me how to get foreground color of this point.

¿Fue útil?

Solución

Use something like this

Element elem=((StyledDocument)jTextPane2.getDocument()).getCharacterElement(position);
StyleConstants.getForeground(elem.getAttributes());
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top