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.
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.
From an answer to your previous question you know that some PL&Fs may clobber the border.
The obvious solution is to therefore override the setBorder
method that the PL&F is calling, and discard the change.
JTextField text = new JTextField() {
@Override public void setBorder(Border border) {
// No!
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With