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

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.