Solved

Focus Problem in JTable

Posted on 2000-04-20
6
1,513 Views
Last Modified: 2010-05-18
I have a problem in retaining the Focus on a particular Cell in a JTable when the data entered in the Cell is invalid.
0
Comment
Question by:hravish040300
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2734839
try this
public void grabFocus() of the JComponent after your validation function ends.
0
 
LVL 2

Expert Comment

by:anand29
ID: 2735031
Instead of using grabFocus() use requestFocus().
0
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2735066
"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. ;)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
jadrek85 earned 20 total points
ID: 2736866
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,

Cheers,
jadrek85
0
 

Author Comment

by:hravish040300
ID: 2737241
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,



0
 

Author Comment

by:hravish040300
ID: 2737380
Hi,

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.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question