Hi,

I want to create a typewrite/typing java app. I want to change the color of a text to be different, whenever the user types the wrong character in a JTextArea. For example, if the user was supposed to type "My Book" and s/he types "My Bok", I want the letter "k" to be displayed in red.

Any helpful input is greatly appreciated.

Thanks.

Good luck, because this is not something you cannot accomplish in one-two weeks. Big teams of programmers spent months on setting this functionality for products like Microsoft Office or Open Office.

And why can't he override paintComponent, setting the color to whatever he wants, using the drawString method to write text, then changing the color when he wants to?

I had seen that also, James, but it said JEditorPane and JTextPane among others, whereas the OP wants to use JTextPane. I guess it might be supported for JTextPane as well though.

paintComponent doesn't solve that problem, because it paints. I need something to be reused. For example, if the user wants to delete a character, it should be deleted.

I had seen that also, James, but it said JEditorPane and JTextPane among others, whereas the OP wants to use JTextPane. I guess it might be supported for JTextPane as well though.

You're right, I think I should go with JTextPane. This is what I was told in forum.java.sun.com. Thanks Jew.

Did you get anywhere with this ChangBroot? I'm trying to do a similar thing, but by placing a smiley in place of some text.

Here's my thread:
http://www.daniweb.com/forums/thread210843.html

Yes, actually, I found out that JTextArea is only for plane AND unformattable text. So, I had to use JTextPane, because it is a child of JEditorPane and add more functionality to JEditorPane. Therefore, for your program, you should use JEditorPane OR JTextPane, cause they give you tons of abilities to manipulate texts, images or icons. Good luck my friend.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.