This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes how would i keep client in textfield of jtable once error thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how would i keep client in textfield of jtable once error thrown" Watch "how would i keep client in textfield of jtable once error thrown" New topic
Author

how would i keep client in textfield of jtable once error thrown

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
I have extended DefaultTableCellRenderer so that when a particular field in a column which is part of a JTable is filled with an invalid entry it turns red. I want this to happen so that the user is aware of their error. My next step which I want to do is to keep the user in that field. What would be the easiest way to go about keeping them in that field, without being able to enter into other fields??
Thanks for your time
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Attach a FocusListener to the field that calls the validation code. If the validation passes, do nothing. If the validation fails, change the background color, and call requestFocus() on the field.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
What happens if the user needs to look the information up somewhere else? They move the mouse to go check and you take them right back. Is this a user requirement?
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
There is no need for them to move back. In the JTable i will have 2 columns one will contain a start date and the 2nd an end date. So im simply checking if the dates entered are correct
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how would i keep client in textfield of jtable once error thrown