954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regarding Java SWT Combo box

Hi all,

I am using a SWT combo box in java. The functionality is like whenever a user enter string in the combos text field, based on that string i am filtering the combos list values and displaying the list using combo.setListVisible(true).

Now, after typing the first letter the list gets displayed and the combos text field is losing focus. So inorder to continuously enter the text the user needs to click in the text field after typing each letter. Is there any fix so that the user can continuously enter the text and the list gets displayed after each new letter typed ?

Thanks.

ynwa
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

A simple requestFocus would probably do the trick, but there might be a more elegant solution. But for that I'd have to actually see some of your code.

Aviras
Junior Poster in Training
82 posts since Jul 2008
Reputation Points: 24
Solved Threads: 8
 

Hi Aviras,

Following is the code i am using. Whwnever i type a letter in combos textfield, on the keyreleased event i am calling a function that will prepare the list values and the list will drop down because of comboLabel.setListVisible(true);.

Now the focus is out of combo's textfield. Is there a way to get the focus back to textfield with out affecting the displayed list ?

comboLabel.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
/*I am calling a function here that will prepare the list values for combo box*/
setLabel(comboLabel.getText());
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
comboLabel.setText(comboLabel.getText());
comboLabel.setListVisible(true);
}
});
}
});

ynwa
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Also requestFocus is in awt, is there any such method for SWT ?

ynwa
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

I found a function forceFocus() for SWT, but together with a warning not to use it. As a matter of fact I'm home in SWT, so my help to you is limited to what I find on google. Here's what I found: http://book.javanb.com/swt-the-standard-widget-toolkit/ch02lev1sec2.html Hope it can answer your questions.

Aviras
Junior Poster in Training
82 posts since Jul 2008
Reputation Points: 24
Solved Threads: 8
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: