【问题标题】:how to get foreground color of particular postion in jtextpane如何在jtextpane中获取特定位置的前景色
【发布时间】:2014-01-06 22:09:22
【问题描述】:

我正在研究具有不同前景色的文本的 jtextpane。我想在不同颜色的文本上设置工具提示。谁能告诉我应该如何在 jtextpane 中获取特定位置或位置的颜色。我通过 jtextpane 上的 StyleConstants.setForeground 方法在文本上设置了不同的前景色。我通过这种方法找到了鼠标的位置。

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

现在我想要这个 ind 变量的前景色。该指示是鼠标所在的特定点。现在谁能告诉我如何获得这一点的前景色。

【问题讨论】:

    标签: java swing tooltip jtextpane foreground


    【解决方案1】:

    使用类似的东西

    Element elem=((StyledDocument)jTextPane2.getDocument()).getCharacterElement(position);
    StyleConstants.getForeground(elem.getAttributes());
    

    【讨论】:

      猜你喜欢
      • 2014-05-12
      • 2013-08-03
      • 1970-01-01
      • 2014-06-10
      • 2011-06-07
      • 1970-01-01
      • 2022-06-12
      • 2014-05-10
      • 2013-10-26
      相关资源
      最近更新 更多