Solved

color border around JTEXTFIELD

Posted on 2002-04-02
3
1,641 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

691 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