Example usage for javax.swing JButton removeActionListener

List of usage examples for javax.swing JButton removeActionListener

Introduction

In this page you can find the example usage for javax.swing JButton removeActionListener.

Prototype

public void removeActionListener(ActionListener l) 

Source Link

Document

Removes an ActionListener from the button.

Usage

From source file:ContainerTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    ContainerListener cont = new ContainerListener() {
        ActionListener listener = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Selected: " + e.getActionCommand());
            }/*from  w ww .j ava 2 s.c  o m*/
        };

        public void componentAdded(ContainerEvent e) {
            Component c = e.getChild();
            if (c instanceof JButton) {
                JButton b = (JButton) c;
                b.addActionListener(listener);
            }
        }

        public void componentRemoved(ContainerEvent e) {
            Component c = e.getChild();
            if (c instanceof JButton) {
                JButton b = (JButton) c;
                b.removeActionListener(listener);
            }
        }
    };

    contentPane.addContainerListener(cont);

    contentPane.setLayout(new GridLayout(3, 2));
    contentPane.add(new JButton("First"));
    contentPane.add(new JButton("Second"));
    contentPane.add(new JButton("Third"));
    contentPane.add(new JButton("Fourth"));
    contentPane.add(new JButton("Fifth"));

    frame.setSize(300, 200);
    frame.show();
}

From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java

private void removeAllListeners(JButton button) {
    for (ActionListener al : button.getActionListeners()) {
        button.removeActionListener(al);
    }//from www . j a  va2  s  .c  o m
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param btn/*  w w w  .ja v  a 2  s  .c o m*/
 * @param url
 */
private void hookupAction(final JButton btn, final URI uri) {
    for (ActionListener al : btn.getActionListeners()) {
        btn.removeActionListener(al);
    }

    if (uri != null) {
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    AttachmentUtils.openURI(uri);
                } catch (Exception e) {
                }
            }
        });
    }
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBoxFromQuery.java

/**
 * @param button/*from ww w.j av a2 s. c o m*/
 */
protected void removeAllActionListeners(final JButton button) {
    for (ActionListener al : button.getActionListeners()) {
        button.removeActionListener(al);
    }
}

From source file:edu.ku.brc.specify.datamodel.busrules.CollectionBusRules.java

@Override
public void initialize(Viewable viewableArg) {
    super.initialize(viewableArg);

    JButton newBtn = null;

    if (formViewObj != null) {
        ResultSetController rsc = formViewObj.getRsController();
        if (rsc != null) {
            if (formViewObj.getMVParent().isTopLevel()) {
                if (rsc.getNewRecBtn() != null)
                    rsc.getNewRecBtn().setVisible(false);
                if (rsc.getDelRecBtn() != null)
                    rsc.getDelRecBtn().setVisible(false);
            } else {
                newBtn = rsc.getNewRecBtn();
            }//from   www .j  a va  2s.  com
        }

        ValCheckBox chkBox = formViewObj.getCompById("6");
        boolean showColEventChkbx = AppPreferences.getLocalPrefs().getBoolean("show.cecheckbox", false);
        chkBox.setVisible(showColEventChkbx);
    }

    if (newBtn != null) {
        // Remove all ActionListeners, there should only be one
        for (ActionListener al : newBtn.getActionListeners()) {
            newBtn.removeActionListener(al);
        }

        newBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                addNewCollection();
            }
        });
    }
}

From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java

public static JComponent getWebsiteDownloadButton(final String title, final String optUrlManualDownloadWebsite,
        final String target_dir_null_ask_user, final String optIntroText, final String[] downloadURLs,
        final String optIntroDialogTitle, final FileDownloadStatusInformationProvider statusProvider,
        final Runnable optFinishSwingTask) {

    final JButton res = new JMButton("Download/Update");
    res.setToolTipText(//from ww w .j a va2  s.c  o  m
            "<html>Click button to start automatic download<br><code><b>Check License/Disclaimers first!");
    res.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            final String opt_local_folder;
            if (target_dir_null_ask_user == null) {
                File file = OpenFileDialogService.getDirectoryFromUser("Select folder");
                if (file == null)
                    return;
                else
                    opt_local_folder = file.getAbsolutePath();
            } else {
                opt_local_folder = target_dir_null_ask_user;
            }

            res.setEnabled(false);
            res.setText("Downloading");
            final BackgroundTaskStatusProviderSupportingExternalCallImpl status = new BackgroundTaskStatusProviderSupportingExternalCallImpl(
                    "Please wait...", "Downloading files...");
            BackgroundTaskHelper.issueSimpleTask(title, "Please wait...", new Runnable() {
                public void run() {
                    boolean allOK = true;
                    for (String downloadURL : downloadURLs) {
                        allOK = performDownload(downloadURL, opt_local_folder, status);
                        if (status.wantsToStop()) {
                            break;
                        }
                    }
                    if (status.wantsToStop()) {
                        allOK = true;
                        try {
                            status.setCurrentStatusText1("Cancel...");
                            for (String downloadURL : downloadURLs) {
                                String fileName = downloadURL.substring(downloadURL.lastIndexOf("/") + 1);
                                if (downloadURL.contains("|"))
                                    fileName = downloadURL.substring(downloadURL.lastIndexOf("|") + 1);
                                String targetFileName = ReleaseInfo.getAppFolderWithFinalSep() + fileName;
                                if (new File(targetFileName).exists()) {
                                    new File(targetFileName).delete();
                                    status.setCurrentStatusText2("Delete " + targetFileName);
                                }
                            }
                        } catch (Exception e) {
                            //
                        }
                    }

                    if (!allOK) {
                        res.setEnabled(true);
                        res.setText(
                                "<html><small>Automatic download failure<br>Click here for manual download");
                        res.removeActionListener(res.getActionListeners()[0]);
                        res.addActionListener(getDialogAction(optUrlManualDownloadWebsite, opt_local_folder,
                                optIntroText, optIntroDialogTitle));
                        res.requestFocus();
                        final JDialog jd = (JDialog) ErrorMsg.findParentComponent(res, JDialog.class);
                        if (jd != null) {
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    jd.pack();
                                }
                            });
                        }
                    } else {
                        if (status.wantsToStop()) {
                            res.setText("Canceled");
                            status.pleaseContinueRun();
                            status.setCurrentStatusText2("Canceled!");
                        } else {
                            res.setText("Downloaded");
                        }
                        res.setEnabled(false);
                        if (statusProvider != null)
                            statusProvider.finishedNewDownload();
                        if (optFinishSwingTask != null)
                            SwingUtilities.invokeLater(optFinishSwingTask);
                    }
                }
            }, null, status);
        }
    });
    return res;
}

From source file:org.ut.biolab.medsavant.client.variant.VariantWorker.java

/**
 * Initialise functionality shared by all UpdateWorkers and PublicationWorkers.
 *
 * @param activity "Importing", "Publishing", or "Removing"
 * @param wizard the wizard which is providing the user interface
 * @param progressLabel label which indicates progress activity
 * @param progressBar provides quantitative display of progress
 * @param workButton starts the process and cancels it
 *//*from w  w  w  .j  av  a 2s.c  om*/
VariantWorker(String activity, WizardDialog wizard, JLabel progressLabel, JProgressBar progressBar,
        JButton workButton) {
    super(activity + "Variants");
    this.activity = activity;
    this.wizard = wizard;
    this.progressLabel = progressLabel;
    this.progressBar = progressBar;
    this.workButton = workButton;

    progressLabel.setText(String.format("%s ...", activity));

    // Convert our start button into a cancel button.
    workButton.setText("Cancel");
    if (workButton.getActionListeners().length > 0) {
        workButton.removeActionListener(workButton.getActionListeners()[0]);
    }
    workButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VariantWorker.this.progressBar.setIndeterminate(true);
            VariantWorker.this.workButton.setText("Cancelling...");
            VariantWorker.this.workButton.setEnabled(false);
            cancel(true);
        }
    });

    workButton.setEnabled(true);
    wizard.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}