title: Java: Swing: Set position of JButton
body: <p>I wanted to realize the following layout:</p>
  
  <pre><code>--------------------------------------------
  |                                          |
  |                                          |
  |                                          |
  |                                          |
  |                                          |
  |                 ----------               |
  |                 |   OK   |               |
  |                 ----------               |
  |                                          |
  --------------------------------------------
  </code></pre>
  
  <p>I wanted to set the size of the button and it shoud be centered in the souther position of the JFrame but it shouldn't have the full width of the JFrame and it shouln't be completly on the bottom of the JFrame, it should have a "margin".
  It would be also possible to set a absolute pixel position of the button because the JFrame has a fixed width/height. At the moment the button has the full JFrame width/height.
  Please notice that the JFrame has a background image.
  My Code:</p>
  
  <pre><code>JFrame j = new JFrame("Foobar");
  BufferedImage myImage = null;
  try {
      myImage = ImageIO.read(new File("background.png"));
  } catch (Exception ex) {}
  
  JPanel p = new ImagePanel(myImage);
  p.setLayout(new BorderLayout());
  
  JButton button = new JButton("OK");
  button.setSize(80, 200);
  button.setFont(new Font("Arial", 1, 40));
  p.add(button);
  f.add(p);
  </code></pre>
  
  <hr>
  
  <pre><code>class ImagePanel extends JPanel {
      private Image image;
      public ImagePanel(Image image) {
          this.image = image;
      }
      @Override
      protected void paintComponent(Graphics g) {
          g.drawImage(image, 0, 0, null);
      }
  }
  </code></pre>