www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - KeyListener with Combo

reply Sam Hu <samhu.samhu gmail.com> writes:
Content-Type: text/plain

Hi ,

I want to practice with KeyListener using Combo which permit the user to enter
text in the text portion of the Combo. As the user types, the list portion of
the Combo is searched for an item that matches the text that has been entered.
If an item is found, it is automatically selected.Attached the source code.But
it does not work.
I don't know what's wrong in the keyPressed() and keyReleased() method.Please
help.
Thanks,
Sam
Sep 10 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
Sam Hu schrieb:
 Hi ,
 
 I want to practice with KeyListener using Combo which permit the user
 to enter text in the text portion of the Combo. As the user types,
 the list portion of the Combo is searched for an item that matches
 the text that has been entered. If an item is found, it is
 automatically selected.Attached the source code.But it does not work.
  I don't know what's wrong in the keyPressed() and keyReleased()
 method.Please help. Thanks, Sam

Can you explain more detailed what is not working? Does it crash? In which line? You can use print statements to find the line. Or does it not select the item? If so, does it execute the path you expect? Also verify this with print statements. For the functionality you want to implement, I see a problem with the KeyListener. What if text is changed by drag and drop or the mouse context menu "paste"? I think the VerifyListener would be good choice.
Sep 11 2008
parent reply Sam Hu <samhu.samhu gmail.com> writes:
Thanks Frank,

What I mean not working is that the combo does not select the text I want.Later
I checked the dwt.dwthelper package and changed the code:
e.toString to dcharToString(e.character) then it works,but can just select when
I enter one letter and can not filter all the possibilities.What I want is ,for
example ,in the combo there are two items:"Banana" and "Bear",when I enter
'b',the combo drops down and shows both "Banana" and "Bear" for selection,then
when I continue to enter 'e',now the "Bear" is selected.

For your advanced suggestion "VerifyLister",I am studying.
Thanks.
Sam
Sep 11 2008
parent Frank Benoit <keinfarbton googlemail.com> writes:
Sam Hu schrieb:
 Thanks Frank,
 
 What I mean not working is that the combo does not select the text I
want.Later I checked the dwt.dwthelper package and changed the code:
 e.toString to dcharToString(e.character) then it works,but can just select
when I enter one letter and can not filter all the possibilities.What I want is
,for example ,in the combo there are two items:"Banana" and "Bear",when I enter
'b',the combo drops down and shows both "Banana" and "Bear" for selection,then
when I continue to enter 'e',now the "Bear" is selected.
 
 For your advanced suggestion "VerifyLister",I am studying.
 Thanks.
 Sam
 

A completely different possiblity, but i don't know if that makes sense for your case... In JFace, there you can have text fields with fieldassist. That is something like autocompletion. See dwt-samples/jface/user/Decoration.d Press Ctrl+Space in the second text field. This behaviour can be customized in a wide range.
Sep 11 2008