title: How can I set size of a button?
body: <p>I put my buttons in a JPane with GridLayout. Then I put JPanel into another JPanel with BoxLayout.Y_AXIS. I want buttons in the GridLayout to be square. I use tmp.setSize(30,30) and it does not work. I also try to use <code>new GridLayout(X, Y, 4, 4)</code> but I cannot figure out what X and Y are. So, what is the correct way to do this stuff?</p>
  
  <p><strong>ADDED:</strong></p>
  
  <p>I still cannot solve the problem. Here is the code of what I am trying to do:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class PanelModel {
      public static void main(String[] args) {
          JFrame frame = new JFrame("Colored Trails");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          JPanel mainPanel = new JPanel();
          mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
  
          JPanel firstPanel = new JPanel();
          firstPanel.setLayout(new GridLayout(4, 4));
          JButton btn;
          for (int i=1; i&lt;=4; i++) {
              for (int j=1; j&lt;=4; j++) {
                  btn = new JButton();
                  btn.setPreferredSize(new Dimension(100, 100));
                  firstPanel.add(btn);
              }
          }
  
          JPanel secondPanel = new JPanel();
          secondPanel.setLayout(new GridLayout(5, 13));
          for (int i=1; i&lt;=5; i++) {
              for (int j=1; j&lt;=13; j++) {
                  btn = new JButton();
                  btn.setPreferredSize(new Dimension(40, 40));
                  secondPanel.add(btn);
              }
          }
  
          mainPanel.add(firstPanel);
          mainPanel.add(secondPanel);
          frame.add(mainPanel);
  
          frame.setSize(400,600);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>The problem is that Java tries to make width of the <code>firstPanel</code> and <code>secondPanel</code> equal! Moreover, Java tries to to fill all height of the window. How can I remove this behavior? </p>