Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1651
  • Last Modified:

color border around JTEXTFIELD

I would like to have a colored border around a JTextField (NOT setting the background color)

Is there a way to do this DIRECTLY (I couldn't find it in the documentation) without resorting to placing the textfield in a colored JPanel or something like that?
0
happyloman
Asked:
happyloman
  • 2
1 Solution
 
mzimmer74Commented:
This should work (haven't tested it though):

JTextField field = new JTextField();
field.setBorder(BorderFactory.createLineBorder(Color.green));



Basically, what you're going to want to do is call field.setBorder(BorderFactory.<something>).  There are a number of things you can do with the BorderFactory, and I'd suggest looking at http://java.sun.com/j2se/1.3/docs/api/javax/swing/BorderFactory.html for more information.  Hope that helps.
0
 
mzimmer74Commented:
Hmm...just tested it and it works for the most part.  However, it doesn't look quite like the standard border.  You may need a beveled border or something like that.  However, the basic concept is there.
0
 
happylomanAuthor Commented:
cool, it looks fine. just what i needed.  I'd only seen borderfactories with panels, never with jtextfields.

THANKS!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now