Java Reference
In-Depth Information
Display 17.15
Some Methods in the Class
AbstractButton
(part 2 of 2)
public
void
setMaximumSize(Dimension maximumSize)
Sets the maximum size of the button or label. Note that this is only a suggestion to the layout man-
ager. The layout manager is not required to respect this maximum size. The following special case
will work for most simple situations. The
int
values give the width and height in pixels.
public
void
setMaximumSize(
new
Dimension(
int
width,
int
height))
public
void
setMinimumSize(Dimension minimumSize)
Sets the minimum size of the button or label. Note that this is only a suggestion to the layout man-
ager. The layout manager is not required to respect this minimum size.
Although we do not discuss the
Dimension
class, the following special case is intuitively clear and
will work for most simple situations. The
int
values give the width and height in pixels.
public
void
setMinimumSize(
new
Dimension(
int
width,
int
height))
The
Dimension
Class
Objects of the class
Dimension
are used with buttons, menu items, and other objects to
specify a size. The
Dimension
class is in the package
java.awt
. The parameters in the fol-
lowing constructor are pixels.
Constructor
Dimension(
int
width,
int
height)
EXAMPLE
aButton.setPreferredSize(
new
Dimension(30, 50));
The
setActionCommand
Method
When the user clicks a button or menu item, that fires an action event that normally
goes to one or more action listeners where it becomes an argument to an
action-
Performed
method. This action event includes a
String
instance variable that is
known as the
action command
for the button or menu item and that is retrieved with
the accessor method
getActionCommand
. The action command in the event is copied
from an instance variable in the button or menu item object. If you do nothing to
change it, the action command is the string written on the button or the menu item.
The method
setActionCommand
given in Display 17.15 for the class
AbstractButton
action
command