0

I am currently developing a program that allows you to change the color of a selected text from a JEditorPane, using setSelectedTextColor (Color.red), but it only temporarily changes the text when I run it with the cursor.

I would like to know how I can set it or change it, as well as the setForeground

c0der
  • 18,467
  • 6
  • 33
  • 65
  • 1
    Please submit a [mre] showing your attempt. – WJS Apr 17 '20 at 22:35
  • Read the section from the Swing tutorial on [Text Component Features](https://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html). It demonstrates how you can use an `Action` to change the attributes of the text. – camickr Apr 17 '20 at 23:15

1 Answers1

0

Maybe this post can help you: Changing color of selected text in jTextPane

This use jTextPane instead of jEditorPane, which I've searched for and says that supports color changes better than jEditorPane.

If that doesn't works, please search in Google for your question and if you find it, we will appreciate you post it here. Thanks.

Lumito
  • 490
  • 6
  • 20
  • I already solved the problem, the code was as follows: `String txtSelect =varModeAdmin.jtxtaText.getSelectedText ();` `String txtModify = varModeAdmin.jtxtaText.getText (). Replace (txtSelect, "" + txtSelect + "< / font> ");` `this.varModeAdmin.jtxtaText.setText (txtModify);` But now I want to know how I can set a foreground, I tried it with the properties menu, but when it runs it doesn't work – Luis Alva Celis Apr 18 '20 at 04:24