I'm trying build a chat, with a simple server and user interface. Every user has a name, and I want the user's name appear in red color and bold before his message, every time he sends a message. Which one (JEditorPane/JTextPane) would be appropriate to my goal? Thanks.
Asked
Active
Viewed 683 times
1 Answers
0
Both of these components will suite your needs just fine. There is no easy way to say which one is better. You can do some backgroudn research and find all the pros and contras yourself.
Here are a few links that will help you started:
-
Thank you! I chose JTextPane, but I don't want the name become red and bold while the user typing, I want just send the string to the server with his name first : outputString = user.getName() + textArea.getText(); I havn't found good guide for my goal.. Can you suggest me one? – Guy Jul 28 '14 at 10:34
-
Since you havent provided any runnable code example, here are a few things that could help you with this. Check these code samples: http://www.coderanch.com/t/341568/GUI/java/JTextArea-changing-color-words and http://stackoverflow.com/questions/6068398/how-to-add-text-different-color-on-jtextpane – Smajl Jul 28 '14 at 10:48
-
Thank you. http://www.java2s.com/Code/JavaAPI/javax.swing/JTextPanesetCharacterAttributesAttributeSetattrbooleanreplace.htm This one is a great example. Then, I thought to build an append function like in the URL (in the server's code) and just append it to all users. What do you think ? :) – Guy Jul 28 '14 at 16:10
-
Can you mark as an answer? Thanks :-) Glad I could help. – Smajl Jul 29 '14 at 06:43