aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to color different colors of the string in a textpane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to color different colors of the string in a textpane" Watch "How to color different colors of the string in a textpane" New topic
Author

How to color different colors of the string in a textpane

prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36
i had used String builder for appending the data and i am converting to string in textpane . so i need different words in different color so how should i do this using This String Builder.
Please help me... Thanks in advance.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

By 'textpane' do you mean JTextPane?


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

StringBuilder doesn't know anything about colours. StyledDocument does, and that's what's being used by JTextPane. Just check out the methods that take an AttributeSet.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36
yes i mean JTextpane
prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36
my program is to append the nos converted to string each time from the for loop so for appending i am using string builder and then converting to string and setting to JTextPane.

my problem is when i am searching one no in the entered JTextPane. that no should appear in color..i am getting that no.. but i am not knowing how to color it ... please help me sir...i need to submit this assignment as soon as possible
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Check out javax.swing.text.Highlighter.
prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36



here in my GUI by clicking on the search button flag becomes true and it checks the if condition in that "currentValueLat" will come from for loop and "getLatSearch()" will be from the user (search value)

and here i need to color that value and sb is the string builder object . appendcolor is a function and i will the code for that



so how to do this i am a beginner for Java... so please help me ... thank you all in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to color different colors of the string in a textpane
 
Similar Threads
MySQL Workbench - how to get the text pane back?
Page size when printing html from JTextPane
Undeline in JTextPane
replaceSelection() in TextPane
Color specifics words in a JTextPane