title: Set JButton background color on windows
body: <p>I have a JButton which I want to set the background to a color.</p>
  
  <pre><code>JButton button = new JButton();
  button.setVisible(true);
  button.setPreferredSize(new Dimension(student_scroll.getWidth(), 50));
  button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
  button.setBackground(Color.BLACK);
  button.setForeground(Color.WHITE);
  button.setOpaque(true);
  </code></pre>
  
  <p>I used this for mac and it showed up as I wanted it to be. However, upon trying it on windows, the foreground is white(as it should) but the background is empty.</p>
  
  <p><a href="https://stackoverflow.com/questions/18165160/setting-background-color-to-jbutton">Setting background color to JButton</a></p>
  
  <p>says to add <code>button.setContentAreaFilled(false);</code> which I did but had no effect. Most others say to add <code>button.setOpaque(true);</code>which I also did already.</p>
  
  <p>What else do I have to do so that it will show up with a black background?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As requested, the SSCCE:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Container;
  import java.awt.Dimension;
  
  import javax.swing.BorderFactory;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.SwingUtilities;
  import javax.swing.UIManager;
  import javax.swing.UnsupportedLookAndFeelException;
  
  public class MainSwing extends JFrame {
      private static final long serialVersionUID = -8231889836024827530L;
  
      public static void main(String[] args) {
          try {
              System.setProperty("apple.laf.useScreenMenuBar", "true");
              System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Test");
              UIManager.put("ScrollBarUI", "main.CustomScrollBarUI");
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch(ClassNotFoundException e) {
              System.out.println("ClassNotFoundException: " + e.getMessage());
      }
      catch(InstantiationException e) {
              System.out.println("InstantiationException: " + e.getMessage());
      }
      catch(IllegalAccessException e) {
              System.out.println("IllegalAccessException: " + e.getMessage());
      }
      catch(UnsupportedLookAndFeelException e) {
              System.out.println("UnsupportedLookAndFeelException: " + e.getMessage());
      }
          SwingUtilities.invokeLater( new Runnable() {
              public void run() {
                  JFrame frame = new JFrame() {
  
                      Container c = getContentPane();
                      JButton button = new JButton("Hello");
                      {
                          button.setText("Hello");
                          button.setVisible(true);
                          button.setPreferredSize(new Dimension(100, 50));
                          button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
                          button.setBackground(Color.BLACK);
                          button.setForeground(Color.WHITE);
                          button.setOpaque(true);
                          c.add(button);
                      }
  
                  };
                  frame.setSize(500, 500);
                  frame.setBackground(Color.BLACK);
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setVisible(true);
              }
          });
      }
  }
  </code></pre>
  
  <p>It seems that the problem has something to do with the line: <code>UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());</code> as when I remove it, the buttons are black.</p>