Solved

text area and  string

Posted on 2002-04-30
9
284 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
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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now