Mega Code Archive

 
Categories / Java / Swing JFC
 

Creating a JButton Component from Action

import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; public class Main {   public static void main(String[] argv) throws Exception {     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 from the action     JButton button = new JButton(action);   } }