Solved

color border around JTEXTFIELD

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 46
xampp tool 12 56
MySqlDump not dumping triggers 1 43
use lov values 2 61
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

839 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