public void addButton(JButton button, String text) { int c = text.charAt(0); if (c >= 'a' && c <= 'z') c = c - 'a' + 'A'; buttons.put(c, button); buttons.put(c + 0x400, button); button.addKeyListener(this); }
public void addComponentKeyListener(KeyListener listener) { btnSave.addKeyListener(listener); btnPrint.addKeyListener(listener); btnReload.addKeyListener(listener); btnFirst.addKeyListener(listener); btnPrevious.addKeyListener(listener); btnNext.addKeyListener(listener); btnLast.addKeyListener(listener); txtGoTo.addKeyListener(listener); btnActualSize.addKeyListener(listener); btnFitPage.addKeyListener(listener); btnFitWidth.addKeyListener(listener); btnZoomIn.addKeyListener(listener); btnZoomOut.addKeyListener(listener); cmbZoom.addKeyListener(listener); }
private static void addButton(JPanel panel, final AgiClientScriptImpl script, KeyPressHandler handler, final char key) { String label = Character.toString(key); JButton button = new JButton(label); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { script.pushChar(key); } }); button.addKeyListener(handler); panel.add(button); }
public void addButtonActionKeyCode(int button, final int keyCode) { final JButton b = getButton(button); if (b != null) { b.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == keyCode) { b.doClick(); } } }); } }
final int yy = y; JButton b = new JButton(); b.addKeyListener(new KeyAdapter()
public static void main(String[] args) { JFrame f = new JFrame(); JButton button = new JButton("Press keys"); button.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_SHIFT) { System.out.println("You pressed Shift"); } else { System.out.println("You pressed a non-Shift key"); // [ more logic ] } } }); f.add(button, BorderLayout.CENTER); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
/** * Creates new form EventsTesterJFrame */ public EventsTesterJFrame() { initComponents(); try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } keyAjButton.addKeyListener(this); keySjButton.addKeyListener(this); keyDjButton.addKeyListener(this); keyWjButton.addKeyListener(this); redirectOutput(); ksession = createKnowledgeSession(); }
/** * Formats the supplied button using the supplied GridBagConstrains, and assigns the supplied Runnable to * the supplied button in such a way that the Runnable is called in a new Thread, so that it does not tie up the UI * * @param button The button to hit for this example * @param runnable the */ protected void initializeButton(JButton button, final Runnable runnable) { button.addKeyListener(keyListener); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { executor.execute(runnable); } }); add(button); }
public class YourClass { JButton isRight; public YourClass() { this.isRight = new JButton(); this.isRight.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { YourClass.this.isRight.getKeyListeners()[0].keyReleased(null); //Other action related code } }); isRight.addKeyListener(new KeyListener() { public void keyReleased(KeyEvent e) { //Key related code } //Other required key listener methods }); } }
void init() { textfield = new JTextField(10); scrollPanel = new ScrollButtonPanel(textfield); displayValue(); scrollPanel.addActionListener(this); scrollPanel.getDecButton().addKeyListener(this); scrollPanel.getIncButton().addKeyListener(this); textfield.addKeyListener(this); textfield.addFocusListener(this); textfield.addActionListener(this); }
void init() { calendar = new GregorianCalendar(); dateFormat = DateFormat.getDateInstance(DateFormat.SHORT); dateFormat.setLenient(true); textfield = new JTextField(10); scrollPanel = new ScrollButtonPanel(textfield); displayDate(); scrollPanel.addActionListener(this); scrollPanel.getDecButton().addKeyListener(this); scrollPanel.getIncButton().addKeyListener(this); textfield.addKeyListener(this); textfield.addFocusListener(this); }
private JPanel getButtonPanel() { btnValidate = new JButton("Validate!"); btnValidate.setPreferredSize(new Dimension(200, 40)); btnValidate.setMnemonic(KeyEvent.VK_V); btnValidate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { validatePressed(); } }); btnValidate.addKeyListener(new KeyAdapter() { /** * Invoked when a key has been pressed. */ public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ENTER) { validatePressed(); } } }); JPanel jpanButtons = new JPanel(); jpanButtons.setLayout(new BoxLayout(jpanButtons, BoxLayout.LINE_AXIS)); jpanButtons.add(Box.createHorizontalGlue()); jpanButtons.add(btnValidate); jpanButtons.add(Box.createHorizontalGlue()); return jpanButtons; }
myButton.addKeyListener(new KeyListener() {
/** * Initializes the OK button action, this will save the settings to the place * @param buttonPanel button panel */ private void initializeOkButton(JPanel buttonPanel) { okButton.setText("OK"); okButton.setMaximumSize(new Dimension(75, 25)); okButton.setMinimumSize(new Dimension(75, 25)); okButton.setPreferredSize(new Dimension(75, 25)); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonHandler(evt); } }); okButton.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { okButtonKeyPressed(evt); } }); GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 9); buttonPanel.add(okButton, gridBagConstraints); }
JButton captureKeyButton = new JButton("Capture key"); JLabel captureText = new JLabel(""); KeyListener keyListener = new KeyAdapter(){ public void keyReleased(KeyEvent e){ KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()); menuItem.setAccelerator(ks); captureText.setText("Key captured: "+ks.toString()); captureKeyButton.removeKeyListener(this); } }; ActionListener buttonClicked = new ActionListener(){ public void actionPerformed(ActionEvent e){ captureKeyButton.addKeyListener(keyListener); captureText.setText("Please type a menu shortcut"); } }; captureKeyButton.addActionListener(buttonClicked);
okay = new JButton("OK"); okay.addActionListener(this); okay.addKeyListener(this); dialog.getRootPane().setDefaultButton(okay); cancel = new JButton("Cancel"); cancel.addActionListener(this); cancel.addKeyListener(this); options = new JButton("Options"); options.addActionListener(this); options.addKeyListener(this); JPanel panel = new JPanel(); panel.add(okay);
cornerButton.addKeyListener(new KeyAdapter() { public void keyPressed(final KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_SPACE) {
button.addKeyListener(this);
JButton button = new JButton("OK"); button.addActionListener(this); button.addKeyListener(this); editorPane.addKeyListener(this); editorPane.addHyperlinkListener(this);
public void register(DockableWindowManagerImpl.Entry entry) { this.entry = entry; dockableName = entry.factory.name; setTitle(entry.shortTitle()); getContentPane().add(BorderLayout.CENTER,entry.win); pack(); Container parent = dockableWindowManager.getView(); GUIUtilities.loadGeometry(this, parent, dockableName); GUIUtilities.addSizeSaver(this, parent, dockableName); KeyListener listener = dockableWindowManager.closeListener(dockableName); addKeyListener(listener); getContentPane().addKeyListener(listener); menu.addKeyListener(listener); entry.win.addKeyListener(listener); setVisible(true); if (! entry.win.isVisible()) entry.win.setVisible(true); } //}}}