title: PaintComponent() not called despite setPreferredSize of JPanel
body: <p>I am trying to understand why the following short piece code does not work.
  I understand that when there are no Layout or the size of the component is 0, the paint component method isn't called. </p>
  
  <p>But this isn't the case here.</p>
  
  <p>Can you explain why I can't set the background for this?</p>
  
  <pre><code>public class Login extends JPanel {
  
      private BufferedImage bgImage;
  
      public Login() {
          super();
          initImages();
          setLayout(new BorderLayout());
  
          setPreferredSize(new Dimension(600, 600));
          add(new JLabel("Hi"), BorderLayout.CENTER);
      }
  
      private void initImages() {
          try {
              bgImage = ImageIO.read(new File("images/login.jpg"));
              System.out.println("image loaded");
          } catch (IOException e) {
              e.printStackTrace();
              System.out.println("image not loaded");
          }
      }
  
      @Override
      public void paintComponents(Graphics g) {
          super.paintComponents(g);
          g.drawImage(bgImage, 0, 0, null);
          System.out.println("repaint");
      }
  
      public static void createAndShowGui() {
          JFrame frame = new JFrame();
          Login login = new Login();
          frame.add(login, BorderLayout.CENTER);
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  createAndShowGui();
              }
          });
      }
  }
  </code></pre>