【问题标题】:How to change the color of a selected text in a JEditorPane?如何更改 JEditorPane 中选定文本的颜色?
【发布时间】:2020-04-19 13:51:47
【问题描述】:

我目前正在开发一个程序,该程序允许您使用setSelectedTextColor (Color.red) 更改从JEditorPane 中选定文本的颜色,但它只是在我使用光标运行时临时更改文本。

我想知道如何设置或更改它,以及setForeground

【问题讨论】:

标签: java swing


【解决方案1】:

也许这篇文章可以帮助你:Changing color of selected text in jTextPane

这使用 jTextPane 而不是 jEditorPane,我已经搜索并说它比 jEditorPane 更好地支持颜色更改。

如果这不起作用,请在 Google 中搜索您的问题,如果找到,我们将非常感谢您在此处发布。谢谢。

【讨论】:

  • 我已经解决了问题,代码如下:String txtSelect =varModeAdmin.jtxtaText.getSelectedText ();String txtModify = varModeAdmin.jtxtaText.getText (). Replace (txtSelect, "<font style = \" color: rgb ("+ color.getRed () +", "+ color.getGreen () +", "+ color.getBlue () +"); \ ">" + txtSelect + "< / font> ");this.varModeAdmin.jtxtaText.setText (txtModify);但是现在我想知道如何设置前景,我用属性菜单试了一下,但是当它运行时它不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
相关资源
最近更新 更多