Solved

Focus Problem in JTable

Posted on 2000-04-20
6
1,502 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
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert ArrayList of custom objects to JSON 4 53
bunnyEars challenge 6 64
countPairs challenge 7 58
Problem to start Neon 20 54
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now