This post originated from an RSS feed registered with Java Buzz
by Scott Delap.
Original Post: RatioLayoutManager: Swing and white space
Feed Title: ClientJava.com
Feed URL: http://www.clientjava.com/archives/wireless_mobile.rdf
Feed Description: Client/Desktop Related Java Development
RatioLayoutManager: Swing and white space I saw this post on clientjava and it got me thinking about an experiment I had done a while back on ratio's and Swing's LayoutManagers. The blog described how to build a window that kept it's ratio of width to height when someone tried to resize it. A while back I thought about using ratios with LayoutManagers to describe what the overall design of your window should look like.
Swing's LayoutManagers are great, but how many times have you put all your components in a frame or dialog, called pack(), looked at the results and replaced the pack() with setSize()? It happens all the time for me. Trying to get Swing's LayoutManagers to look pleasing is a hard task without hard coding the size of something. The LayoutManagers use preferred size to achieve what they think is aesthically pleasing. They sum all the preferred sizes up and figure that's what's pleasing. However, if you set the component's preferred size you're ultimately hard coding the size of the components. Using preferred size starts to undo the whole point of LayoutManagers.