All pastes #24805 Raw Edit

KeyMap test

public java v1 · immutable
#24805 ·published 2005-10-07 04:31 UTC
rendered paste body
package test;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Test extends JFrame{	public Test()	{		super("test");				JTextArea ta = new JTextArea();				JPanel p = new JPanel(new BorderLayout());		p.add(new JScrollPane(ta), BorderLayout.CENTER);				JButton button = new JButton("Close");				button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F12, KeyEvent.CTRL_DOWN_MASK), "QUIT");		button.getActionMap().put("QUIT", new AbstractAction() {			public void actionPerformed(ActionEvent e)			{				setVisible(false);			}		});		p.add(button, BorderLayout.NORTH);		getRootPane().setDefaultButton(button);				setContentPane(p);		setAlwaysOnTop(true);		setSize(400, 400);				setLocationRelativeTo(null);	}			public static void main(String[] args) 	{		SwingUtilities.invokeLater(new Runnable() {			public void run()			{				new Test().setVisible(true);			}		});	}			}