Solved

text area and  string

Posted on 2002-04-30
9
321 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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 50 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 160
java imports not found 4 68
Tomcat 9 + java 8 error while trying to deploy a war file 2 839
Eclipse neon2 "Java build path" correctness 7 40
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

738 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