Reputation: 23035
Please have a look at the below code
Border border = BorderFactory.createLineBorder(Color.RED, 1);
introducerFeesTxt.setBorder(border);
I used this code to create a line border for the JTextField
. However now I need to remove it and replace it's normal view. Below is what I tried.
introducerFeesTxt.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
That code above again created a border which is not similar to other normal JTextFields. Below is a screenshot.
You can clearly see the differnece between the "Normal" JTextField
and the JTextField with the added border. How can I reset it to be "normal" ?
Upvotes: 2
Views: 742
Reputation: 17971
You could keep the original border in a variable before change it and then use this border to set it back to its original state:
Border originalBorder;
...
JTextField textField = new JTextField(20);
originalBorder = textField.getBorder();
// here you can safely change text field's border
Of course the scope of this originalBorder
variable should be wide enough to use it when needed (f.e.: class member).
Note: Please note this approach is independent of the PLAF used by your application.
Upvotes: 3
Reputation: 11327
You should use the original border from the L&F (Look and Feel).
Border border = BorderFactory.createLineBorder(Color.RED, 1);
introducerFeesTxt.setBorder(border);
// some operation
introducerFeesTxt.setBorder(UIManager.getBorder("TextField.border"));
Upvotes: 2