Jeetesh Nataraj
Jeetesh Nataraj

Reputation: 608

JTable Focus Related Query?

In Jtable when Tab key is pressed the focus shifts to the next cell of the table. If have to restrict the movement, is there any possible way of doing it....

Thank You in advance....

Upvotes: 0

Views: 145

Answers (2)

camickr
camickr

Reputation: 324118

if focus reaches end of row(0), it should not be enter row

You need to replace the default left/right Action with a custom Action of your own.

You can choose to write your own Action. It would not be that difficult. All you would need to do is invoke changeSelection(...) method of the table with the next column number.

Or Table Tabbing show how you can reuse the existing Action. This is probably not required for this requiement, but it may be helpful for more complex requirements.

Upvotes: 1

Behrang Saeedzadeh
Behrang Saeedzadeh

Reputation: 47913

JTable table = ...;
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "none");
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), "none");

Upvotes: 1

Related Questions