Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

One issue in popup/setfocus that I would like to get clarified..  RSS feed

 
Sriram Sharma
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is a concern that I have in my project.
The project is in Java Swing. The issue is something like this...

I have 2 screens - Page 1 and page 2.
When I move from page1 to page2, I need to validate the fields present in page1. If any field is invalid, I need to prompt the user with a popup alert. Once the user clicks the "OK" button in popup, the focus should be set to the field where the error occurred.
I actually goto a different class and if any error occurs, I throw the exception from the called class, catch the exception in the calling class and then show a popup dialog box stating that the field is invalid. Now, once this is done, the focus should go back to the text field which had a wrong entry. There are nearly 8 such fields and based on the field which had invlid entry, I need to show the focus at respective field. Can somebody help me in this? Thanks in advance.

Regards,
Sriram.
 
Ajay A Patil
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Have a separate try/catch block for each of those 8 textfields.

OR

2. Dont use try/catch. Have your called method, return true/false
to indicate if user input is valid.
 
Sriram Sharma
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but, wont it be a child like way to handle 1 try catch block for each of the 8 fields? Is it professional? Some experienced facts/guidance/suggestion required...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this might be one way you could do it

only problem is you have to tab out of the final textfield to enable the page 2 button.
possibly could add a documentlistener to check doc length, changing validated
status, then iterating tf[] to see whether the button should be enabled.

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mving to Swing/AWT forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!