문제

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.

도움이 되었습니까?

해결책

Use something like this

Element elem=((StyledDocument)jTextPane2.getDocument()).getCharacterElement(position);
StyleConstants.getForeground(elem.getAttributes());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top