title: Change Border Color of a JButton in Java Swing preserving the insets
body: <p>I want to change the border color of a JButton component in Java Swing.</p>
  
  <p>I have tried the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.example.test;
  
  import java.awt.Color;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.BorderFactory;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.UIManager;
  import javax.swing.UnsupportedLookAndFeelException;
  
  public class Test extends JFrame {
  
      public Test() {
  
          JPanel panel = new JPanel();
          JButton button1 = new JButton("Test Button 1");
          JButton button2 = new JButton("Test Button 2");
          button2.setBorder(BorderFactory.createLineBorder(Color.RED));
  
          panel.add(button1);
          panel.add(button2);
  
          this.add(panel);
  
  
          setSize(400, 400);
          setVisible(true);
  
      }
  
      public static void main(String[] args) {
  
          try {
              UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
          } catch (ClassNotFoundException ex) {
              Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
          } catch (UnsupportedLookAndFeelException ex) {
              Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
          }
          Test t = new Test();
      }
  }
  </code></pre>
  
  <p>This generates two buttons, on button2 component I try to change border color but it removes the padding. Is there anyway to preserve the original insets of a standard JButton and just change the color?</p>
  
  <p>Note: I assume that the insets are being removed when assigning the new Border. But I am not 100% sure about it.</p>
  
  <p><a href="https://i.stack.imgur.com/T5huI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T5huI.png" alt="JButton Change Border Color"></a></p>