Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How do I implement this dialog behavior?
How do I implement this dialog behavior? [message #461018] Wed, 14 September 2005 18:29 Go to next message
Eclipse UserFriend
Originally posted by: gilbert.pilz.sbc-guesstherest.net

I have a dialog that has two text fields (URL and user name) and two
buttons (Connect and Cancel). I want to implement the following behavior:

1.) If the user tries to press Connect and either of the two text fields
are empty the dialog automatically refocuses on the empty text field.

2.) If the user presses <enter> while the focus is on either of the text
fields the dialog behaves as if the Connect were pressed (including the
validation performed in (1).

I've already implemented (1) by using a FocusListener on the Connect
button. I figure I can do (2) by adding a KeyListener to the text fields
that watches for <enter> and does "the right thing". I'm worried that
this might cause some weird behavior if one of the text fields is empty.
I'm also wondering if there is some more elegant way of implementing
this. Also, is there some way of visually cueing the user that the
Connect button will be pressed if they hit <enter>?

- g
Re: How do I implement this dialog behavior? [message #461125 is a reply to message #461018] Fri, 16 September 2005 16:01 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
The correct way to do #2 is with Shell.setDefaultButton(yourConnectButton).
This will give you the desired Enter behaviour with no work required on your
end, and a visual cue on the Connect button as well.

Grant

"Gilbert Pilz" <gilbert.pilz@sbc-guesstherest.net> wrote in message
news:dg9q4m$b59$1@news.eclipse.org...
> I have a dialog that has two text fields (URL and user name) and two
> buttons (Connect and Cancel). I want to implement the following behavior:
>
> 1.) If the user tries to press Connect and either of the two text fields
> are empty the dialog automatically refocuses on the empty text field.
>
> 2.) If the user presses <enter> while the focus is on either of the text
> fields the dialog behaves as if the Connect were pressed (including the
> validation performed in (1).
>
> I've already implemented (1) by using a FocusListener on the Connect
> button. I figure I can do (2) by adding a KeyListener to the text fields
> that watches for <enter> and does "the right thing". I'm worried that
> this might cause some weird behavior if one of the text fields is empty.
> I'm also wondering if there is some more elegant way of implementing
> this. Also, is there some way of visually cueing the user that the
> Connect button will be pressed if they hit <enter>?
>
> - g
Previous Topic:Tree: "Good Practice" when base domain doesnŽt represent Tree structure?
Next Topic:Image size cannot be changed after first setImage in SWT Table using Win32
Goto Forum:
  


Current Time: Wed Apr 24 21:31:06 GMT 2024

Powered by FUDForum. Page generated in 0.02552 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top