title: How to set a size for a JPanel inside a JFrame?
body: <p>I am trying to put a JPanel in the center of a fullscreen JFrame with a defined size, but it's always stretching for the whole screen...</p>
  
  <p>I tried <code>setBounds</code>, <code>setPreferredSize</code>, but they don't work.</p>
  
  <p>This is the code:</p>
  
  <pre><code>public static void showScene(){
  //Create the frame to main application.
      JFrame frame = new JFrame("Application"); // set the title of the frame
      frame.setExtendedState(JFrame.MAXIMIZED_BOTH);  // set the size, maximum size.
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      //Create the panel to store the main menu.
      JPanel panel = new JPanel();
  
      panel.setPreferredSize(new Dimension(500,200));
      panel.setBackground(new java.awt.Color(0,0,255));
  
      frame.add(panel,BorderLayout.CENTER);
  
  }
  
  public static void main (String[] args){
  
      showScene();
  
  }
  </code></pre>