Solved

color border around JTEXTFIELD

Posted on 2002-04-02
3
1,637 Views
Last Modified: 2007-12-19
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
Comment
Question by:happyloman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:mzimmer74
ID: 6913315
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
 
LVL 2

Accepted Solution

by:
mzimmer74 earned 200 total points
ID: 6913316
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
 

Author Comment

by:happyloman
ID: 6913375
cool, it looks fine. just what i needed.  I'd only seen borderfactories with panels, never with jtextfields.

THANKS!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
null output 3 43
Problem to Alipay 10 72
java example issue 5 46
Bot application - advice 3 64
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question