Focus Problem in JTable

I have a problem in retaining the Focus on a particular Cell in a JTable when the data entered in the Cell is invalid.
Who is Participating?
jadrek85Connect With a Mentor Commented:
Hi hravish!

use following code to set focus to perticuler cell on the JTable.

JTable.editCellAt(0,0); // this will sets the focus to 1st cell on 1st row and col
JTable.removeEditor();// this will remove focus from 1st cell

Hope this will solve ur problem. Good Luck,

try this
public void grabFocus() of the JComponent after your validation function ends.
Instead of using grabFocus() use requestFocus().
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

"Set the focus on the receiving component. This method is for focus managers, you rarely want to call this method, use requestFocus() enstead."

I thought the requestFocus() was the first thing hravish has done. ;)
hravish040300Author Commented:
Hi jadrak85,

As per your suggetion I included the code.It works fine only when the user presses either Tab key or Enter key.If user try to navigate to different cell by  using Mouse then the target cell gets the Focus which is not desirable.

Is there any way to control mouse action also.

Thanks and regards,

hravish040300Author Commented:

I found a simple work around. By raising some Exception we can make the focus retained in the editing cell.The same trick is used in Developer 2000 forms by raising unhandled exception to retain the focus on the editing Textfield.

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.

All Courses

From novice to tech pro — start learning today.