title: Getting the size of a JButton inside a JPanel that has a GridLayout
body: <p>I have a <code>JPanel</code> that has a <code>GridLayout</code>. To this grid layout I add <code>JButton</code> objecs. I want to add background images to the buttons, but I don't know what size to specify the images because I am not able to get the correct size of the buttons in the grid layout. When I call <code>getHeight()</code> and <code>getWidth()</code> as well as <code>getPreferedSize()</code> I get faulty data. How can I know what size to make the images so that I can add them to the buttons? </p>
  
  <p>Here is the way I am trying to implement this - what is missing is adding the images to the button.</p>
  
  <pre><code>public class CustomPanel extends JPanel{
  
      final int GRIDHEIGHT = 4;
      final int GRIDLENGTH = 6;
  
      public CustomPanel(){
          super();
          init();
      }
  
      public void init(){
  
          setLayout(new GridLayout(GRIDHEIGHT, GRIDLENGTH, 10, 10));
          setBorder(new EmptyBorder(10, 10, 10, 10) );
  
          for(int i = 0;i&lt;GRIDHEIGHT;i++){
              for( int j=0;j&lt;GRIDLENGTH;j++){
                   button = new JButton("(" + i + ", " + j + ")");
  
                   add(button);
          }
      }
  }
  </code></pre>