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);
Post a comment