package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

public class MainPanel extends JPanel {
    private final JPanel panel = new JPanel(new GridLayout(1, 2, 5, 5));
    private final JSpinner spinner = new JSpinner(new SpinnerNumberModel(9, 0, 100, 1));
    private Integer value = 9;

    public MainPanel() {
        super(new BorderLayout(5, 5));

        final JPanel p1 = new TestPanel();
        p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
        p1.add(Box.createHorizontalGlue());
        p1.add(makeLabel());
        p1.add(Box.createHorizontalGlue());

        final JPanel p2 = new TestPanel();
        p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
        p2.add(Box.createVerticalGlue());
        p2.add(makeLabel());
        p2.add(Box.createVerticalGlue());

        for (JPanel c: Arrays.asList(p1, p2)) {
            c.setBackground(Color.WHITE);
            panel.add(c);
        }

        spinner.addChangeListener(new ChangeListener() {
            @Override public void stateChanged(ChangeEvent e) {
                JSpinner s = (JSpinner) e.getSource();
                value = (Integer) s.getValue();
                p1.revalidate();
                p2.revalidate();
            }
        });

        JPanel np = new JPanel(new GridLayout(1, 2));
        np.add(new JLabel("BoxLayout.X_AXIS", SwingConstants.CENTER));
        np.add(new JLabel("BoxLayout.Y_AXIS", SwingConstants.CENTER));

        JPanel sp = new JPanel(new BorderLayout());
        sp.add(new JLabel("MinimumSize: "), BorderLayout.WEST);
        sp.add(spinner);

        add(np, BorderLayout.NORTH);
        add(panel);
        add(sp, BorderLayout.SOUTH);
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setPreferredSize(new Dimension(320, 240));
    }

    private JLabel makeLabel() {
        JLabel l = new JLabel("abc") {
            @Override public Dimension getPreferredSize() {
                return new Dimension(50, 50);
            }
            @Override public Dimension getMinimumSize() {
                Dimension d = super.getMinimumSize();
                if (Objects.nonNull(d)) {
                    d.width = value;
                    d.height = value;
                }
                return d;
            }
        };
        l.setOpaque(true);
        l.setBackground(Color.ORANGE);
        l.setFont(l.getFont().deriveFont(Font.PLAIN));
        l.setAlignmentX(Component.CENTER_ALIGNMENT);
        l.setAlignmentY(Component.CENTER_ALIGNMENT);
        l.setVerticalAlignment(SwingConstants.CENTER);
        l.setVerticalTextPosition(SwingConstants.CENTER);
        l.setHorizontalAlignment(SwingConstants.CENTER);
        l.setHorizontalTextPosition(SwingConstants.CENTER);
        return l;
    }

    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class TestPanel extends JPanel {
    @Override protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2);
        g.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight());
    }
}

@@ -150,24 +150,47 @@
 ava.util.*;%0A
+import java.util.List;%0A
 import javax
@@ -272,81 +272,8 @@
 l %7B%0A
-    private final JPanel panel = new JPanel(new GridLayout(1, 2, 5, 5));%0A
     
@@ -360,39 +360,8 @@
 1));
-%0A    private Integer value = 9;
 %0A%0A  
@@ -423,38 +423,32 @@
 , 5));%0A%0A        
-final 
 JPanel p1 = new 
@@ -645,22 +645,16 @@
         
-final 
 JPanel p
@@ -859,383 +859,308 @@
     
-for (JPanel c: Arrays.asList(p1, p2)) %7B%0A            c.setBackground(Color.WHITE);%0A            panel.add(c);%0A        %7D%0A%0A        spinner.addChangeListener(new ChangeListener() %7B%0A            @Override public void stateChanged(ChangeEvent e) %7B%0A                JSpinner s = (JSpinner) e.getSource();%0A                value = (Integer) s.getValue();%0A                p1.revalidate();
+JPanel panel = new JPanel(new GridLayout(1, 2, 5, 5));%0A        List%3CComponent%3E list = Arrays.asList(p1, p2);%0A        for (Component c: list) %7B%0A            c.setBackground(Color.WHITE);%0A            panel.add(c);%0A        %7D%0A%0A        spinner.addChangeListener(e -%3E %7B%0A            for (Component c: list) %7B
 %0A   
@@ -1172,18 +1172,17 @@
         
-p2
+c
 .revalid
@@ -2140,23 +2140,57 @@
     
-d.width = v
+int i = ((Integer) spinner.getValue()).intV
 alue
+()
 ;%0A  
@@ -2213,22 +2213,21 @@
   d.
-height = value
+setSize(i, i)
 ;%0A  

use Dimension#setSize(i, i) instead of d.width = i; d.height = i;