I have an object that I want to be be a perfect square no matter how large the window gets, but I don't want it to be restricted to a certain size (aka, as big as it can get within the window). The problem is, I have an empty border for padding around it that I want to also adjust in proportion with the size. The problem is, every time I use setBorder() in the paint method (where I've been putting all my re-size code), it doesn't work. I think it's creating an infinite loop but I'm not sure. Anyone know what the problem is and how I can fix this?
setBorder() is likely to call repaint() when set, similar to setIcon() etc,
so an infinite loop seems probable.
if you want your squareObject to remain the same size, regardless of window size,
add it to a GridBagLayout JPanel, with default GridBagConstraints. The squareObject
will be located in the center of the panel, with the panel taking up all additional space.
Joined: Mar 11, 2012
But I don't. I want it to always stay the largest it can, just with a border that changes in proportion with the window size.
Joined: Jun 09, 2003
perhaps setting the border in ComponentListener's componentResized() might suit