constrained resize

March 7, 2008 on 7:45 pm | In Swing |

OK, I have a JFrame whose dimensions had to be constrained on resize. Basically, it has to grow equally in width and height (think Checkerboard). In order to do that, I had to override the JFrame’s setBounds. However, I had no idea how to apply this same behavior when teh Frame is maximized. When maximized, the Frame would simply blow up and fit the entire screen. Well, it turns out that the same way setSize has been deprecated, setMaximiumSize - although not deprecated, it’s ignored for Frames. So use setMaximizedBounds.


   Rectangle bounds = getGraphicsConfiguration().getBounds();
   int minOfSizes = (int) Math.min(bounds.getWidth(), bounds.getHeight());
   setMaximizedBounds(new Rectangle(new Dimension(minOfSizes, minOfSizes))); // viola!

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. how dare they intro a method i’ve not heard off since the last time i used Swing in 1998.. those bastards..

    Comment by xrellix — March 8, 2008 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^