I have implemented a JTable in JScrollpane. I have added MouseListener to the JTable, so its working fine with MouseListener.
Now my problem is, the row selection changes by the Keyboard Arrow ke开发者_如何学Cys(up arrow/down arrow) also and it does not call the methods that I have already implemented with MouseListener. So i just want to remove the JTable selection by Keyboard arrows.
Kindly help me.
Swing components use Key Bindings to invoke Action when a give KeyStoke is entered.
From reading the above tutorial link you should be able to remove the key bindings by using code like:
InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put(KeyStroke.getKeyStroke("DOWN", 0), "none");
I'll let you handle the up key.
JTable has ListSelectionModel. You can get it with method getSelectionModel(). Then you can add ListSelectionListener to ListSelectionModel by method addListSelectionListener(ListSelectionListener).
精彩评论