public Text() {
this.setBounds(200, 200, 600, 500);
JTextPane pane = new JTextPane();
pane.setText("ABCDEFG");
this.add(pane);
setVisible(true);
} public static void main(String[] args) {
new Text();
}
提供代码如上:要求: (1)屏蔽Ctrl+A不能选中文字
(2)如果按Ctrl+A则文本JTextPane 输出~A
this.setBounds(200, 200, 600, 500);
JTextPane pane = new JTextPane();
pane.setText("ABCDEFG");
this.add(pane);
setVisible(true);
} public static void main(String[] args) {
new Text();
}
提供代码如上:要求: (1)屏蔽Ctrl+A不能选中文字
(2)如果按Ctrl+A则文本JTextPane 输出~A
ctrl+a是操作系统级别的
跟alt+f4类似
if (e.isControlDown()) {
e.setKeyCode(-1);
}不知道还有没有其他更好的方法
Action doNothing = new AbstractAction(){
@Override public void actionPerformed(ActionEvent e){}
};JTextPane textpane = ...;
textpane.getInputMap().put(ctrlA,"DO_NOTHING");
textpane.getActionMap().put("DO_NOTHING",doNothing);
按下Ctrl A什么都不做。
输出~A 你自己修改一下Action的实现。