| |
e743. Creating a JButton Component
Although it is possible to create a button with just a label, it is
highly recommended to use an action to create a button. The action can
then be shared by other components such as a toolbar.
// Create an action
Action action = new AbstractAction("Button Label") {
// This method is called when the button is pressed
public void actionPerformed(ActionEvent evt) {
// Perform action...
}
};
// Create the button
JButton button = new JButton(action);
e744.
Changing the Label of a JButton Component
e745.
Creating a Multiline Label for a JButton Component
e746.
Adding an Icon to a JButton Component
e747.
Moving the Icon in a JButton Component
e748.
Moving the Label/Icon Pair in a JButton Component
e749.
Setting the Gap Size Between the Label and Icon in a JButton Component
e750.
Adding a Disabled Icon to a JButton Component
e751.
Adding a Rollover and Pressed Icon to a JButton Component
© 2002 Addison-Wesley.
|