简体   繁体   中英

remove row selection by arrow keys in jtable

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM