wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How do you set the color of an array List of JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do you set the color of an array List of JTextArea" Watch "How do you set the color of an array List of JTextArea" New topic
Author

How do you set the color of an array List of JTextArea

Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

These are defined in the field.

These are defined in the method.


What i'm trying to do is the following:
1. Scan for a String and make it the name of the player
2. That name then gets assigned a user specified color via JColor Chooser
3. The data is stored in an arrayList of type Player, which is defined in the Player class
4. I then add type player to the GUI by using a JTextArea

Here's where I'm having trouble.
5. The displayed text should show the specified color in step 2.

getColor cannot be used for type Color: it wants me to change it to a string. However, that is not what I want to do.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816


You can't set the color to an ArrayList. May be on a JTextArea? Extract each element in the ArrayList then add set the color....


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I don't think you can set every line of a JTextArea to a different color. Why don't you use a JList? Then you can specify the colour for each cell.
And I don't think you want a nested loop.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you set the color of an array List of JTextArea
 
Similar Threads
JOptionPane.showOptionDialog
JColor Chooser - JLabels?
How do you add objects to arrays?
Arrays - Exception error
Can JLabels print string from an array list