title: JTextField - Reset Border to System Default
body: <p>I am trying to color the <code>Border</code> of a <code>JTextField</code> red and then change it back to "normal" later on. When I am using Linux (furthermore Ubuntu), the initial <code>Border</code> differs from the <code>Border</code> that you get by using <code>UIManager.getBorder("TextField.border");</code> one of them is a <code>SynthBorder</code> and one is a <code>FieldBorder</code>. The "correct" one would be the <code>SynthBorder</code>.</p>
  
  <p>SSCCE:</p>
  
  <pre><code>import javax.swing.BorderFactory;
  import javax.swing.BoxLayout;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JTextField;
  import javax.swing.UIManager;
  import javax.swing.UnsupportedLookAndFeelException;
  
  public class Main
  {
    private static boolean switched;
  
    public static void main( final String[] args )
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
    {
      UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
  
      JFrame frame = new JFrame( "Test border change" );
      frame.getContentPane().setLayout( new BoxLayout( frame.getContentPane(), BoxLayout.LINE_AXIS ) );
      JTextField tf = new JTextField();
      JButton button = new JButton( "Switch" );
      button.addActionListener( action -&gt;
      {
        if ( switched )
        {
          tf.setBorder( UIManager.getBorder( "TextField.border" ) );
          switched = !switched;
        }
        else
        {
          tf.setBorder( BorderFactory.createLineBorder( Color.RED ) );
          switched = !switched;
        }
      } );
      frame.getContentPane().add( tf );
      frame.getContentPane().add( button );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      frame.pack();
      frame.setVisible( true );
    }
  }
  </code></pre>
  
  <p>I have already tried:</p>
  
  <ul>
  <li>using <code>JComponent.updateUI()</code> (no effect)</li>
  <li>nulling the border (ruins the layout)</li>
  <li>preserving it (not a proper way)</li>
  </ul>
  
  <p>Does anyone have a better idea?</p>