?? mainframe.java~10~
字號:
package jkeymapdemo;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;import javax.swing.text.*;public class MainFrame extends JFrame { private JPanel contentPane; private BorderLayout borderLayout1 = new BorderLayout(); private JTextField jTextField1 = new JTextField(); private JLabel jLabel1 = new JLabel(); //Construct the frame public MainFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(407, 75)); this.setTitle("JKeyMapDemo"); jTextField1.setFont(new java.awt.Font("SansSerif", 0, 14)); contentPane.add(jTextField1, BorderLayout.CENTER); contentPane.add(jLabel1, BorderLayout.SOUTH); Action[] actionList = this.jTextField1.getActions(); for (int i=0;i<actionList.length;i++){ if (actionList[i].getValue(Action.NAME)==DefaultEditorKit.cutAction){ Action a = actionList[i]; KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_1,Event.CTRL_MASK); this.jTextField1.getKeymap().addActionForKeyStroke(ks,a); } if (actionList[i].getValue(Action.NAME)==DefaultEditorKit.copyAction){ Action a = actionList[i]; KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_2,Event.CTRL_MASK); this.jTextField1.getKeymap().addActionForKeyStroke(ks,a); } } } } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -