2013-12-18 29 views
1

我正在使用具有不同前景色的文本的jtextpane。我想在不同的彩色文字上設置工具提示。任何人都可以告訴我,我應該如何在jtextpane中獲取特定位置或位置的顏色。我在文本上設置了不同的前景色jtextpane上的StyleConstants.setForeground方法。我用這種方法找到了鼠標的位置。如何在jtextpane中獲取特定位置的前景色

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

現在我想要這個ind變量的前景色。這個ind是鼠標所在的特定點。現在誰能告訴我如何獲得這一點的前景色。

回答

1

使用這樣的

Element elem=((StyledDocument)jTextPane2.getDocument()).getCharacterElement(position); 
StyleConstants.getForeground(elem.getAttributes()); 
相關問題