Java JButton addActionToButton(JButton button, final Runnable action)

Here you can find the source of addActionToButton(JButton button, final Runnable action)

Description

add Action To Button

License

Open Source License

Declaration

public static void addActionToButton(JButton button, final Runnable action) 

Method Source Code


//package com.java2s;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

public class Main {
    public static void addActionToButton(JButton button, final Runnable action) {
        button.addActionListener(new ActionListener() {
            @Override/*from   w w  w  .j av  a 2 s  .  c om*/
            public void actionPerformed(ActionEvent e) {
                action.run();
            }
        });
    }
}

Related

  1. addCRListener(JComponent c, final JButton b)
  2. addEnterListener(JComponent c, final JButton b)
  3. adjustButtonMargins(Insets margin, JButton... buttons)
  4. adjustButtonWidth(JButton button, int minWidth, int minHeight)