[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

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?
0
gla
Asked:
gla
  • 3
  • 3
  • 2
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
hoomanvCommented:
yeah I missed it
you can pass a null instead
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now