去掉 Ctrl + A 全选

时间:2022-05-29 17:32:19
 
 
 1 import java.awt.*;  2 import java.awt.event.*;  3 import javax.swing.*;  4 import javax.swing.table.*;  5  
 6 public class Table {  7     public static void main(final String[] args) {  8         java.awt.EventQueue.invokeLater(new Runnable(){  9                 public void run(){ 10                     DefaultTableModel model = new DefaultTableModel(5,10){ 11                             public Object getValueAt(int r,int c){ 12                                 return Integer.valueOf(r*c); 13  } 14                             public boolean isCellEditable(int r,int c){ 15                                 return false; 16  } 17  }; 18                     JTable table = new JTable(model); 19                     final InputMap im = new ComponentInputMap(table); 20                     final ActionMap am = new ActionMap(); 21                     im.put(KeyStroke.getKeyStroke("ctrl a"),"donothing"); 22                     am.put("donothing",null); 23  table.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW,im); 24  table.setActionMap(am); 25                     JFrame frame = new JFrame("Table"); 26  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 27                     frame.getContentPane().add(new JScrollPane(table)); 28  frame.pack(); 29                     frame.setLocationRelativeTo(null); 30                     frame.setVisible(true); 31  } 32  }); 33  } 34 }