Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
Width and height can be stored in a java.awt.Dimension object. An instance is made by the Component method getSize.
When the button is clicked, the contentpane's size is stored in a Dimension object referred to by cd .
A Dimension's width and height can be accessed as `shown here .
String representations of the other Dimension objects are made because we use String concatenation .
Next, given the contentpane and button sizes, we calculate where to put the button it so it will be exactly at the bottom center of the contentpane.
Position it .
To make this last, we disable the flowlayout manager. If you definitely want to manage the layout yourself, you can issue this statement in the init method .
We advise against it, though, because then you're responsible for everything having to do with the layout :
- setting component sizes, while taking into account the font size
- setting locations
- calculating so they don't overlap
All pixel-based, so resolution-dependent, a LOT of work.
Much better to let the layout manager classes, like FlowLayout, take this off your hands ( or most of it, anyway ).