Disabling selection of next line in a JTable: is this possible?

My application has a JTable with a custom editor defined on one of the columns.  What I'd like to do is to disable the JTable from selecting the next line when the user hits the Return key.  I know that pressing the Return key commits the change to the data being displayed.  I want to prevent the JTable from changing the selection to the next line after committing the change.  Is this possible?  If so, how do I do it? If you can, please either include a code snippet in your reply or point me to where I can see some code that does this.  Thanks in advance.
mwalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

javaexpertoCommented:
What I do is this:
I  make a KeyListener and put an if:

if (myTable.isFocusOwner() && e.getKeyCode() == 10)

the code 10 is for the return key. Next, you get the selected row(it will be the next you selected) and create an object to select your own row. The last step is select the interval (rows). As the JTable selects the next row when you press enter key, you only need to select the previous row and it appears that nothing happened. (Actually the JTable has selected again the row  where user hits return key but you don't notice this)
public void keyPressed(KeyEvent e) {
    if (myTable.isFocusOwner() && e.getKeyCode() == 10) {
        int selectedRow = myTable.getSelectedRow();
        ListSelectionModel selectionModel = myTable.getSelectionModel();
        selectionModel.setSelectionInterval(selectedRow - 1, selectedRow - 1);
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mwalkerAuthor Commented:
That worked for me. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.