I have a JComponent that does custom drawing, and overrides the following methods:
public Dimension getPreferredSize() {
return new Dimension(imageWidth, imageHeight);
}
public Dimension getMinimumSize() {
return new Dimension(imageWidth, imageHeight);
}
Where imageWidth and imageHeight are the actual size of the image.
I have added it to the content pane using SpringLayout:
layout.putConstraint(SpringLayout.SOUTH, customComponent, -10, SpringLayout.SOUTH, contentPane);
layout.putConstraint(SpringLayout.EAST, customComponent, -10, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, customComponent, 10, SpringLayout.NORTH, contentPane);
So it is constrained to the north and south so that it will resize its height when it is resized, and the east is constrained to the edge of the content pane, but the west is free to move left.
I would like it to maintain a square size (width == height) when it is resized. Anyone have any idea how to do this?