Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

On focuslost ()

Thread view: 
Suchitra - 26 Nov 2004 15:05 GMT
Hi there!
  I'm stuck on a technical difficulty while I was implementing the
validation logic for quite a few days.

My validation logic is invoked on focuslost event of an editable combo.
There are Ok and Apply button on the dialog will save the setting in a
file.

Now, if I edit the combo setting and then immediately click
the OK button.
The very first event called is the FocusLost after which it
should ideally work on the enqueued event which actually caused it. But it
doesn't call my OK button handler.
I have to again press an click to save it.

Why does it focuslost event eat the ACtionEVent ?
Is there any work-around for this ?

I'll appreciate any kind of help.
Thanks
John McGrath - 27 Nov 2004 08:57 GMT
> I'm stuck on a technical difficulty while I was implementing the
> validation logic for quite a few days.
>
> My validation logic is invoked on focuslost event of an editable combo.

Have you tried using an InputVerifier?

Signature

Regards,

John McGrath

Suchitra - 29 Nov 2004 04:56 GMT
Nopes. Can you explain something more about this ?
Andrew Thompson - 29 Nov 2004 05:12 GMT
> Nopes. Can you explain something more about this ?

<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/InputVerifier.html>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

John McGrath - 30 Nov 2004 04:44 GMT
> Nopes. Can you explain something more about this ?

javax.swing.InutVerifier.

Check the Sun site for more information.  InputVerifier is covered in the
Java Tutorial, and one of the sample chapters for a Swing book posted
there covers the subject in detail.

Signature

Regards,

John McGrath

Suchitra - 29 Nov 2004 05:10 GMT
Actually, problem is because the validation logic is happening
on the server side and hence spawned on a different worker thread.

My Event-Dispatch thread needs to wait till this thread returns back as it
can't save the settings till then.

Some pointers would really help.
Thanks
John McGrath - 30 Nov 2004 05:01 GMT
> Actually, problem is because the validation logic is happening
> on the server side and hence spawned on a different worker thread.

That sounds like a very different problem than what you described in your
previous message.  But it certainly does present some challenges.

If you need to connect to a server to do some part of the validation, you
do not want to do that at the field level, at least not synchronously.
That would slow things down and it would freeze the UI if you have some
sort of network slowdown or failure.

The easiest solution would be to do these validations at the form level.
When the user presses OK or whatever he does to commit the changes, you
would then do the server-based validations.  As an alternative, you could
do these in a background thread and use some sort of indicator in the UI,
such as changing the text color to red, to indicate errors in the values.

> My Event-Dispatch thread needs to wait till this thread returns back as
> it can't save the settings till then.

No, you do not want the Event Dispatch Thread waiting on any process that
is not guarateed to complete quickly.  You should consider your validation
to be a "long-running process", so you need to do the validation in a
separate thread.

Signature

Regards,

John McGrath

Babu Kalakrishnan - 29 Nov 2004 07:53 GMT
>    I'm stuck on a technical difficulty while I was implementing the
> validation logic for quite a few days.
[quoted text clipped - 12 lines]
> Why does it focuslost event eat the ACtionEVent ?
> Is there any work-around for this ?

I find this hard to believe. Are you sure you aren't getting the
ActionEvent from the button ? (Try just putting in some debug println
statements in the focuslost as well as the ActionEvent handler).

If you're certain you're "losing" the actionevent, please post a code
sample that exhibits this behaviour - I'm sure it has to do with
something you're doing in your focus handler.

And as a general rule of thumb, performing validation in a focusLost
handler is generally trouble-prone. Try looking at an InputVerifier as
another poster suggested. (though I vaguely recall some discussion about
even InputVerifiers not behaving too well in complex components such as
a ComboBox : I've never used one on a JComboBox - so cannot offer any
feedback on how well it works)

BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.