Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #5198
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | markspace <-@.> |
| Newsgroups | comp.lang.java.gui |
| Subject | Re: Passing KeyEvent upward |
| Date | Sun, 22 Jul 2012 17:39:13 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 70 |
| Message-ID | <jui6fj$47d$1@dont-email.me> (permalink) |
| References | <0f05834e-c654-4925-b78a-b8328b23ba0b@googlegroups.com> <jui5n3$vq$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Mon, 23 Jul 2012 00:39:15 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="4333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NQZadVpjjqJE8RPfevf1H09HIVB9PiBU=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 |
| In-Reply-To | <jui5n3$vq$1@dont-email.me> |
| Cancel-Lock | sha1:yqTYChlknvdH7Gc28HI/qhyGlJE= |
| Xref | csiph.com comp.lang.java.gui:5198 |
Show key headers only | View raw
On 7/22/2012 5:26 PM, markspace wrote:
> Sounds like an accelerator to me.
Here's the simplest example I could think of. Tell me if it works like
what you want.
package quicktest;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
/**
*
* @author Brenden
*/
public class Accelerator {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
JTextArea ta = new JTextArea();
frame.add(ta);
JMenuBar mbar = new JMenuBar();
JMenu file = new JMenu("File");
mbar.add(file);
JMenuItem blarg = new JMenuItem("blarg");
blarg.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_1, ActionEvent.ALT_MASK));
blarg.addActionListener( new Blarg( ta ) );
file.add(blarg);
frame.setJMenuBar(mbar);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize( 400, 400 );
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
private static class Blarg implements ActionListener {
private final JTextArea ta;
public Blarg(JTextArea ta) {
this.ta = ta;
}
@Override
public void actionPerformed(ActionEvent e) {
ta.append( " blarg" );
}
}
}
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar
Passing KeyEvent upward Adam Beneschan <adam@irvine.com> - 2012-07-22 16:09 -0700
Re: Passing KeyEvent upward markspace <-@.> - 2012-07-22 17:26 -0700
Re: Passing KeyEvent upward markspace <-@.> - 2012-07-22 17:39 -0700
Re: Passing KeyEvent upward Adam Beneschan <adam@irvine.com> - 2012-07-23 21:15 -0700
Re: Passing KeyEvent upward markspace <-@.> - 2012-07-23 23:08 -0700
Re: Passing KeyEvent upward "John B. Matthews" <nospam@nospam.invalid> - 2012-07-22 21:32 -0400
Re: Passing KeyEvent upward Roedy Green <see_website@mindprod.com.invalid> - 2012-07-23 23:46 -0700
Re: Passing KeyEvent upward Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2012-07-24 13:15 -0700
Re: Passing KeyEvent upward Adam Beneschan <adam@irvine.com> - 2012-07-24 21:08 -0700
Re: Passing KeyEvent upward markspace <-@.> - 2012-07-24 22:50 -0700
Re: Passing KeyEvent upward Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-25 00:32 +0200
csiph-web