?
Solved

Focus Problem in JTable

Posted on 2000-04-20
6
Medium Priority
?
1,516 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
Industry Leaders: 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 60 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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