Search code examples
javaswinguser-interfaceborderjtextfield

Removing the added border from JTextField and bringing it back to normal


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.

enter image description here

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" ?


Solution

  • 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"));