Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Changing focus when the component is being activated.(Dynamically create the items for Combo box based on inputs)
Changing focus when the component is being activated. [message #875999] Wed, 23 May 2012 14:01 Go to next message
Eclipse UserFriend
Hi,

I have a couple of input components on my SWT dialog. One of the input component is a Combo; but its choices depend on the "values" from the other input Text.

What I did is that I put a Listener on the "Activate" event for the combo box and at that time, try to capture the "values" from the other input Text components. If a component is "empty", I will popup a MessageBox and then I tried to switch focus to that "Text" component. But this switching doesn't seem to work since the focus is always back on the Combo. Does anyone have recommendations or maybe can point to what I do wrong here:

myCombo.addListener(SWT.Activate, new Listener() {
	public void handleEvent(Event e) {
		if (!errorEncounterd) {
			setChoices(myCombo);
		} else {
			e.doit = false;
			errorEncounterd = false;
		}
	}
});


private void setChoices(Combo myCombo) {
	String input = myInputText.getText();
	if (input.trim().length() == 0)
	{
		myInputText.setFocus();
	}
}
Re: Changing focus when the component is being activated. [message #876024 is a reply to message #875999] Wed, 23 May 2012 15:14 Go to previous messageGo to next message
Eclipse UserFriend
maybe it doesn't work, since you are still in the SWT.Activate event. just guessing ... have you tried something like this:

myInputText.getDisplay().asyncExec(new Runnable() {
	public void run() {
		myInputText.setFocus();
	}
});
Re: Changing focus when the component is being activated. [message #876039 is a reply to message #876024] Wed, 23 May 2012 15:45 Go to previous message
Eclipse UserFriend
Thanks very much. That works...
Previous Topic:How can I use SashForm with any layout other than FillLayout
Next Topic:Showing the system out (from logger) into a text.
Goto Forum:
  


Current Time: Sat Aug 30 20:04:20 EDT 2025

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

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

Back to the top