Here you can find the source of addCRListener(JComponent c, final JButton b)
Parameter | Description |
---|---|
c | the given component |
b | the given button |
public static void addCRListener(JComponent c, final JButton b)
//package com.java2s; //License from project: Open Source License import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JComponent; public class Main { /**// w ww .ja va 2 s .co m * Pressing Enter on the given component will act as clicking * on the given button. * * @param c * the given component * @param b * the given button */ public static void addCRListener(JComponent c, final JButton b) { c.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { b.doClick(); } } }); } public static void addCRListener(JButton b) { addCRListener(b, b); } }