本文整理了Java中javax.swing.JButton.addKeyListener()
方法的一些代码示例,展示了JButton.addKeyListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JButton.addKeyListener()
方法的具体详情如下:
包路径:javax.swing.JButton
类名称:JButton
方法名:addKeyListener
暂无
代码示例来源:origin: org.jclarion/clarion-runtime
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);
}
代码示例来源:origin: jasperreports/jasperreports
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);
}
代码示例来源:origin: org.onebusaway/onebusaway-phone
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);
}
代码示例来源:origin: org.japura/japura-gui
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();
}
}
});
}
}
代码示例来源:origin: stackoverflow.com
final int yy = y;
JButton b = new JButton();
b.addKeyListener(new KeyAdapter()
代码示例来源:origin: stackoverflow.com
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);
}
代码示例来源:origin: salaboy/jBPM5-Developer-Guide
/**
* 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();
}
代码示例来源:origin: vgrazi/java-concurrent-animated
/**
* 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);
}
代码示例来源:origin: stackoverflow.com
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
});
}
}
代码示例来源:origin: org.appdapter/org.appdapter.lib.gui
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);
}
代码示例来源:origin: org.appdapter/org.appdapter.lib.gui
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);
}
代码示例来源:origin: uk.ac.ebi.pride.validator/prideValidator
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;
}
代码示例来源:origin: stackoverflow.com
myButton.addKeyListener(new KeyListener() {
代码示例来源:origin: sarahtattersall/PIPE
/**
* 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);
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: sc.fiji/Fiji_Plugins
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);
代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui
cornerButton.addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_SPACE) {
代码示例来源:origin: mucommander/mucommander
button.addKeyListener(this);
代码示例来源:origin: net.imagej/ij
JButton button = new JButton("OK");
button.addActionListener(this);
button.addKeyListener(this);
editorPane.addKeyListener(this);
editorPane.addHyperlinkListener(this);
代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit
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);
} //}}}
内容来源于网络,如有侵权,请联系作者删除!