Get JTextField

Setting the color of JTextField is done like so:textField.setBorder( new LineBorder(Color.red, 2) );but then how do you get the color of a JTextField?
[171 byte] By [blackmagea] at [2007-11-27 9:58:52]
# 1
You used setBorder, so what prevents you from using getBorder ?ICE
icewalker2ga at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...
# 2
Doesn't return the color.
blackmagea at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...
# 3

You didn't set a color, you set a border. Hence it will return a border, from which you can probably get the color.

Color c = ((LineBorder)textField.getBorder()).getLineColor();

Do you per chance happen to have the Java API on your machine? Somethings can be solved by taking 3 secs to check the API. If you dont have it then I suggest you download it NOW.

ICE

icewalker2ga at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...
# 4
Yea I read the API, thats how I got the first one to work. And the way you gave doesn't work either.
blackmagea at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...
# 5
> And the way you gave doesn't work either. Of course it does.How many times have you been asked to post a SSCCE showing what you are doing? We can't possibly guess what you are doing wrong. Its only a single line of code.
camickra at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...
# 6

> Yea I read the API, thats how I got the first one to work. And the way you gave doesn't work either.

Well if the code snippet given didn't work then read the API again, this aint magic, so the answer should be in there somewhere.

I have to ask, are you trying to set background color or a border color? Cause from the code you provided then, you are working with borders not colors, the colors are an added effect. Try to be clear on what you want then, maybe your problem can be solved.

ICE

icewalker2ga at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...
# 7
I got it. It creates a class cast exception because I'm going from LineBorderClass to EtchedBorderClass so I just added a try-catch statement in, thnx.
blackmagea at 2007-7-13 0:29:46 > top of Java-index,Desktop,Core GUI APIs...