change color on a selected text in jEditorPanel

I have a jEditorPanel with setContentType("text/html") and some text and I want to set color or change font (html) on selected text or set html code in cursor position.
any idea?
glaAsked:
Who is Participating?
 
hoomanvCommented:
yeah I missed it
you can pass a null instead
0
 
sciuriwareCommented:
I did:

      pane.setSelectedTextColor(Color.BLACK);
      pane.setSelectionColor(Color.YELLOW);

;JOOP!
0
 
glaAuthor Commented:
ok this is true if added the html code..

but i want to insert text (html) like "<strong>" in a cursor position for example:

the text in jEditorPanel is:

language JAVA

the cursor position is between language and java like:

language | java

and when I click on a button the text will change to:

language <strong> java..
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sciuriwareCommented:
The simplest way is to collect the contents             String x = pane.getText();
know the caret position              pane.getCaretPosition();
to insert or replace the text you want
and then put it back                 pane.setText(x);

;JOOP!
0
 
hoomanvCommented:
pane.getDocument().insertString(pane.getCaretPosition(), your text here);
0
 
glaAuthor Commented:
hoomanv

the insertString() has another on option the Attribute
0
 
glaAuthor Commented:
the comments that help me is the following(I accept wrong comment by mistake):

hoomanv:
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html

see the TextComponentDemo
http://java.sun.com/docs/books/tutorialJWS/uiswing/components/example-1dot4/TextComponentDemo.jnlp

hoomanv:
pane.getDocument().insertString(pane.getCaretPosition(), "your text here", null);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.