File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Need a help on developing multicolored textarea for chat application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need a help on developing multicolored textarea for chat application" Watch "Need a help on developing multicolored textarea for chat application" New topic
Author

Need a help on developing multicolored textarea for chat application

daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Hi friends,
I have made a chat application for the net using sockets and it has all the features like pms and rooms etc, but i am using a text area for posting the meesages on the client, now in most sites we have say the private meesages in red and rest in black and so on and also we have images whihc we can put there, what shall i use for that? because if i try to change color of text area the whole color of page will change by setForeground() not that of a single line, anyone can advice me? ill be thankful
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi daman,
you will have to use JTextPane for this purpose. because JTextarea does not support multiple colors.
for details u can go through the tutorial for JTextpane on sun's site.
regards
deekasha

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by daman sidhu:
Hi friends,
I have made a chat application for the net using sockets and it has all the features like pms and rooms etc, but i am using a text area for posting the meesages on the client, now in most sites we have say the private meesages in red and rest in black and so on and also we have images whihc we can put there, what shall i use for that? because if i try to change color of text area the whole color of page will change by setForeground() not that of a single line, anyone can advice me? ill be thankful

Hi Daman,
Let me get u correctly. U r trying to change the foreground color of the textarea. U can do it though the color class. Here is the working code. Pl. feel free to ask more details.
import java.applet.*;
import java.awt.*;
public class Test extends Applet
{
TextArea txtFld1 = new TextArea(2,10);
Color clr = new Color(255,0,0);
public void init()
{
add(txtFld1);
txtFld1.setForeground(clr);
}
}

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by daman sidhu:
Hi friends,
I have made a chat application for the net using sockets and it has all the features like pms and rooms etc, but i am using a text area for posting the meesages on the client, now in most sites we have say the private meesages in red and rest in black and so on and also we have images whihc we can put there, what shall i use for that? because if i try to change color of text area the whole color of page will change by setForeground() not that of a single line, anyone can advice me? ill be thankful

Hi! Daman,
Here is the working code to change the foreground of textarea.
import java.applet.*;
import java.awt.*;
public class Test extends Applet
{
TextArea txtFld1 = new TextArea(2,10);
Color clr = new Color(255,0,0);
public void init()
{
add(txtFld1);
txtFld1.setForeground(clr);
}
}
daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
HI Buddies thanks for the replies, well as for changing the foregound color using setForegournd() that does change but the problem is u see that the color of the whole foregournd including previous messages change, not of one particular line that i want , for this i will try to use JTextPane as a freind o sugests here but u see- browser does not support swings as of yet as per my knowledge so i may have to send the swings.jar file along with the archive tag of applet ? will that be the answer ? do let me know ,
Thnks
Daman
daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Originally posted by deekasha gunwant:
Hi daman,
you will have to use JTextPane for this purpose. because JTextarea does not support multiple colors.
for details u can go through the tutorial for JTextpane on sun's site.
regards
deekasha
hi deeksha
thanks for repying but do IE and netscape support swings? or will i have to send the swings.jar in the archive of applet? i will try that textpane thing surely though thanks again.
Regards
Daman


Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Yes, it is possible. try the html converter. visit the sun following site http://java.sun.com/products/plugin/
daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Hi Again,
theres one more thing Deeksha i wanted to know- which particular do i need to use in particular for that purpose- there are no methods directly of JTextPane but there are methods setSelectedColor() and getSelectedInex() of JTextComponent inherited by it, will i have to use them? ill really be grateful if u could include a small bit of code.
Regards,

Daman
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi Daman,
as kishore has already suggested that swing can be used in an applet by converting ur html file using html converter.
for textpane
visit the following link.
http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html
I'm busy right now. but I'll try to write a small code for u.
and in case u get it first do post it here because many of us will get benefit out of it.
regards
deekasha
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi daman,
hopefully u must have got a multicolored textpane by now. still I'm posting a small code for a multicolored textpane .

---------------------------------------------

---------------------------------------------

regards
deekasha
daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Hello deksha,
First of all i would like to thank you for helping me out with the problem i was facing, really i am very thankful to the advice i got from all the guys ,and most of all you , my chat program is almost ready now and if anybody would need advice on that i would be most obliging, thanks again,
Regards,
Daman
daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Hi Deekhsha,
Im here to trouble u again- LOL , the code u gave me is working fine but theres no scrollbars in textpane, and i didnot find any method to add one in it, would scrollpane work with the same methods? what shall i do and yes one more thing- that html converter thing works fine with applets but what im doing here is that i have a applet only for the login name and room selection but i instantiate a frame from that applet in which is the real GUI interface, how do i get that working because html converter works with applets only, should i then provide the swings file in a jar file with the archive tag?? Plz do let me know ill be thankful,
Regards,
Daman
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi daman,
to get scrollbars just add your textpane to JScrollPane.and this Jscrolpane to your contentpane.
e.g.
JScrollPane jspane = new JScrollPane(yourtextpane);
yourapplet.getContentPane().add(jspane);
hopefuly this will solve your problem.
Now next one.
html converter works for applet as well as any frame that u r opening from that applet.and if u say it does not work I won't believe it because I've worked with a project in which we were having applet just for logging in and the main GUI was contained in a diffrent JFrame that open up after successful login.

regards
deekasha

daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
HI Deeksha theres one more thing, LOL i keep troubling u, im sorry but u have to help me- look if i use html converter and run that in browser it asks me to download the plugin from the suns site which is about 5 mb , so that means that if a client on the net wants to chat, hell have to download the module?? that does not sound a very good idea considering also that it takes considerable time to download over the net? Plz advice me, ill be thankful, and believe me i am very thankful till now for all the help and advice ive got from u, uve got to help me now through the end LOL
Regards and thanks ,
Daman
daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
HI again,
Ha i posted a few replies myself as i progressed here but the thing is the program is working now with htmlconverter but its not really feasable for each client to download the plugin, is there a work around?? Plz let me know,
Daman
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need a help on developing multicolored textarea for chat application