title: How to set component size inside container with BoxLayout
body: <p>I'm facing a problem with using <code>BoxLayout</code>.</p>
  
  <p>In my example, I try to decrease the height of the text field and change the width of the buttons (as shown in green marker in the picture at the bottom). I know about the techniques <code>setPreferredSize()</code> and <code>setMaximumSize()</code>, but it did not work as it should. The line <code>add(Box.createHorizontalGlue())</code> also did not help.</p>
  
  <p>Thanks for any ideas.</p>
  
  <hr>
  
  <pre><code>public class Testy extends JPanel {
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  constructGUI();
              }
          });
      }
  
      private static void constructGUI() {
          JFrame frame = new JFrame("Testy");
          frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  
          JPanel centerPanel = new JPanel();
          centerPanel.setBackground(Color.DARK_GRAY);
          centerPanel.setPreferredSize(new Dimension(100, 400));
          frame.add(centerPanel, BorderLayout.CENTER);
  
          Testy eastPanel = new Testy();
          frame.add(eastPanel, BorderLayout.EAST);
  
          frame.pack();
          frame.setVisible(true);
      }
  
      public Testy() {
          setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
  
          JButton button = new JButton("Button ...... 1");
          //button.setPreferredSize(...);
          //button.setMaximumSize(...);
          add(button);
  
          button = new JButton("Button 2");
          //button.setPreferredSize(...);
          //button.setMaximumSize(...);
          add(button);
  
          button = new JButton("Button ........... 3");
          //button.setPreferredSize(...);
          //button.setMaximumSize(...);
          add(button);
  
          JLabel label = new JLabel("Label");
          //label.setPreferredSize(...);
          //label.setMaximumSize(...);
          add(label);
  
          JTextField textField = new JTextField();
          //textField.setPreferredSize(...);
          //textField.setMaximumSize(...);
          add(textField);
  
          button = new JButton("Button 4");
          //button.setPreferredSize(...);
          //button.setMaximumSize(...);
          add(button);
  
          //add(Box.createHorizontalGlue());
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Q9pOQ.png" alt="picture"></p>