Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

text area and  string

Posted on 2002-04-30
9
Medium Priority
?
330 Views
Last Modified: 2006-11-17
Sir,
   I have to display the string "hello world" in a single text area in a frame (or applet) . String "hello" should be displayed in (say) blue
color and "world " in (say) red color.how can i proceed?
thanks
paramjit
ver -- JDK 1.3
0
Comment
Question by:paramibm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6980442
Homework? We're here to help people who have *already* produced something of their own.
0
 
LVL 35

Expert Comment

by:girionis
ID: 6980477
 Hehehehe, CEHJ could not be more right.
0
 

Author Comment

by:paramibm
ID: 6980556
sir
i had done a project in java to create Multithreaded Chat server .
 thanks
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 18

Expert Comment

by:bobbit31
ID: 6981099
use a JTextArea (in this example, named jta) and then do something like:

jta.select(0, 5);
jta.setSelectedTextColor(Color.red);
jta.select(5, 10);
jta.setSelectedTextColor(Color.blue);
0
 

Expert Comment

by:sunilvirus
ID: 6983964
i am also having the same problem(slightly different).
see my question "Displaying colors in textfield"

one useful link given in my following is
http://developer.java.sun.com/developer/onlineTraining/GUI/Swing2/Magercises/M3/index.html

i think it will serve your purpose.
0
 

Expert Comment

by:sunilvirus
ID: 6988072
hello bobbit31

your code in not working as required.
when using the method setSelectedTextColor() for the second time,
the color applied in the first call is not being retained.
it is again changing back to the foreground color.

this is because the previous selection is lost when the new text is selected.
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 6989097
you could use a JTextPane to have formatted text... in this case, I set the content type to "text/html":

public class ColorText extends JApplet {
   
    private JTextPane jtp;
       
    public void init()
        {
           jtp = new JTextPane();
           jtp.setContentType("text/html");
           getContentPane().add(jtp);

           jtp.setText("<font color=#0000FF>This is <b>Blue</b></font> <font color=#FF0000>This is <b>Red</b></font>");
     }
}
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992747
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: bobbit31
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8048333
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question