Creating image buttons of the correct size

Article ID: 1027
Last updated: 05 Feb, 2008
Article ID: 1027
Last updated: 05 Feb, 2008
Revision: 1
Views: 2686
Posted: 09 Mar, 1998
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


I am unable to create an ImageButton where the image is the same size as the button. I try to use the setSize() member function, but this does not seem to change the ImageButton. the way I want it to.


Cause


The getPreferredSize() member function of ImageButton overrides the setSize() function inherited from the canvas class.


Action


You will probably want to create a derived class from ImageButton that always returns the minimum size. This will produce an ImageButton that uses the size of the smallest associated button.

class MinimumSizedButton extends ImageButton {

public MinimumSizedButton(SerializableImage image) {
super(image);
}

public Dimension getPreferredSize() {
return getMinimumSize();
}
}
This article was:   Helpful | Not helpful
Report an issue
Article ID: 1027
Last updated: 05 Feb, 2008
Revision: 1
Views: 2686
Posted: 09 Mar, 1998 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category