Solved

color border around JTEXTFIELD

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 85
Where to store the queries for modification of table 4 64
stackato and cloud 4 87
Apps blocked by Java 9 82
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 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