Java Reference
In-Depth Information
Display 17.15
Some Methods in the Class
AbstractButton
The abstract class
AbstractButton
is in the
javax.swing
package.
All of these methods are inherited by both of the classes
JButton
and
JMenuItem
.
public void
setBackground(Color theColor)
Sets the background color of this component.
public void
addActionListener(ActionListener listener)
Adds an
ActionListener
.
public void
removeActionListener(ActionListener listener)
Removes an
ActionListener
.
public void
setActionCommand(String actionCommand)
Sets the action command.
public
String getActionCommand()
Returns the action command for this component.
public void
setText(String text)
Makes text the only text on this component.
public
String getText()
Returns the text written on the component, such as the text on a button or the string for a
menu item.
public void
setPreferredSize(Dimension preferredSize)
Sets the preferred size of the button or label. Note that this is only a suggestion to the layout
manager. The layout manager is not required to use the preferred size. The following special
case will work for most simple situations. The
int
values give the width and height in pixels.
public void
setPreferredSize(
new
Dimension(
int
width,
int
height))
public void
setMaximumSize(Dimension maximumSize)
Sets the maximum size of the button or label. Note that this is only a suggestion to the layout
manager. 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
manager. 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))