Hi Friends, I have a canvas in a chat applet where all the messages are being drawn/displayed send by different users. Now, the problem is - the width of a canvas is fixed. Now, the problem is when the user types a message the length of which is more than the canvas width, the message gets cuts when the canvas width exceeds. I want the canvas when the width of message exceeds, the rest of the message should be displayed on the next line. Also, I want the word wrapping feature ?? What should I do ? I hope there is of course someone to help me !! Regards and thanx in advance.
Here is a link to the FontMetrics docs: http://java.sun.com/j2se/1.3/docs/api/java/awt/FontMetrics.html You can get a FontMetrics object by calling the method getFontMetrics(Font font) on your canvas. There are functions in the class that return values for the height and width of characters or strings for that font. For example, to find the width of a string in Arial 12pt plain text:
Hi Angela, I think word wrapping in textarea is possible if you remove the horizontal scrollbar. But yes, writing in diffrent colors, I assume would be a problem. But then you can always change the Foreground color of a text you are writing. But if you have to draw an image on a textarea, I dont know how will you ? Many chat applets are doing this including yahoo.com and rediff.com. If possible , do tell me what they are using , a textarea or a canvas, because they are drawing images also. I doubt if images can be drawn on a textarea. Regards and thanks,
You are right about the word wrapping, my mistake. I can't say for sure what Yahoo uses for their chat applet, since I haven't seen the source code, but I'm pretty sure it must be a custom Canvas component. TextArea can't draw images and will only show text in one font and color. And if they were using JTextArea, which does support images and different fonts and colors, then the applet would require the JRE plugin.