Results 1 to 11 of 11
Thread: JTextArea
- 03-28-2010, 04:49 PM #1
JTextArea
I have
and when I doJava Code:public void sM(String s, Color c) { jTextArea1.setForeground(c); String textAreaText = jTextArea1.getText(); jTextArea1.setText(textAreaText + s + "\n"); }the text stays blue, but I want it to be in different colors.Java Code:sM("Hello", Color.red); sM("Hello", Color.blue);
-
You'll probably need to delve into using either JTextPane or JEditorPane. The tutorials can show you how, but it's a bit more complex then using JTextAreas.
- 03-28-2010, 05:30 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,383
- Blog Entries
- 7
- Rep Power
- 17
- 03-28-2010, 05:33 PM #4
I think I am doing something wrong to my sM method, because when I do
the text is like this :Java Code:sM("Hello", Color.red); sM("Hello", Color.blue);
Hello
Hello.
But I want it to be like:
Hello
Hello.
- 03-28-2010, 05:35 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,383
- Blog Entries
- 7
- Rep Power
- 17
- 03-28-2010, 05:37 PM #6
- 03-28-2010, 05:45 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,383
- Blog Entries
- 7
- Rep Power
- 17
-
- 03-28-2010, 06:11 PM #9
-
You will have to study the tutorials. As I noted, using a JTextPane or JEditorPane is not as straight forward as using JTextArea as I believe that you might need to use SytledDocuments, AttributeSets, EditorKits, etc... (it's been a while since I've looked at this). You may also be able to get different colors by using HTML tags, but I've not tried this myself. The tutorials and the API can get you started, but plan on needing a little time to study it before you can get it implemented.
Again much luck.
- 03-28-2010, 06:17 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,383
- Blog Entries
- 7
- Rep Power
- 17
I wonder if you actually did read all replies. Well, did you? If so why are you stubbornly trying to accomplish something that can only be done that (ludicrous) way in your imagination?
kind regards,
Jos
ps. A Color is not a String, nor will a JTextArea understand it, and read the API to see if a setForeground( ... ) method returns a value. hint: it doesn't so it can't be used in way you are trying to do.
Similar Threads
-
JTextArea on PopUp -JTextArea isn't editable
By Richy76 in forum AWT / SwingReplies: 3Last Post: 02-01-2010, 07:51 PM -
adding jtextarea
By xhoneyskye in forum AWT / SwingReplies: 4Last Post: 01-26-2010, 03:46 AM -
Tab key in JTextArea
By KristoZ in forum New To JavaReplies: 1Last Post: 09-25-2009, 07:27 PM -
About JTEXTAREA
By makpandian in forum AWT / SwingReplies: 4Last Post: 03-19-2009, 06:53 AM -
JTextArea
By saytri in forum New To JavaReplies: 0Last Post: 01-13-2008, 01:07 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks