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
Solved

Focus Problem in JTable

Posted on 2000-04-20
6
1,509 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
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.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

856 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