Java JButton Settings configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel)

Here you can find the source of configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel)

Description

configure OK And Cancel Buttons

License

Apache License

Declaration

public static void configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel) 

Method Source Code

//package com.java2s;
// License:   Apache Software License (Version 2.0)

import java.awt.event.KeyEvent;
import javax.swing.Action;
import javax.swing.ActionMap;

import javax.swing.InputMap;

import javax.swing.JComponent;

import javax.swing.JPanel;
import javax.swing.KeyStroke;

public class Main {
    public static void configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel) {
        final ActionMap actionMap = panel.getActionMap();
        final InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        if (cancel != null) {
            actionMap.put(cancel.getValue(Action.ACTION_COMMAND_KEY), cancel);
            inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancel.getValue(Action.ACTION_COMMAND_KEY));
        }/*from  w ww  .java  2 s .  co  m*/
        if (ok != null) {
            actionMap.put(ok.getValue(Action.ACTION_COMMAND_KEY), ok);
            inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ok.getValue(Action.ACTION_COMMAND_KEY));
        }
    }
}

Related

  1. applyDefaultProperties(final Button comp)
  2. askYesNoQuestion(String dlgTitle, String question, Component parent, Object[] buttonTittle)
  3. buttonGroup(AbstractButton b1, AbstractButton b2)
  4. buttonGroup(JToggleButton b1, JToggleButton b2)
  5. clickButton(final Window window, final String buttonText)
  6. configureTextAndMnemonic(AbstractButton button, String text)
  7. confirm(Component comp, String title, String message, int buttons, int type)
  8. creaStyledButton(int style)
  9. customize(AbstractButton btn)