Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there anyway to remove a border in a JTextField?

txt = new JTextField();
txt.setBorder(null);   // <-- this has no effect.

I would really want it to look like a JLabel - but I still need it to be a JTextField because I want people to be able highlight it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
255 views
Welcome To Ask or Share your Answers For Others

1 Answer

JTextField textField = new JTextField();
textField.setBorder(javax.swing.BorderFactory.createEmptyBorder());

http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html

When setting the border to 'null', you're actually telling the look & feel to use the native border style (of the operating system) if there is one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...