开发者

remove row selection by arrow keys in jtable

开发者 https://www.devze.com 2023-04-13 02:26 出处:网络
I have implemented a JTable in JScrollpane. I have added MouseListener to the JTable, so its working fine with MouseListener.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消