Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsSet focus problem in editor
https://www.eclipse.org/forums/index.php/mv/msg/162300/513228/#msg_513228
I enter certain values in text box2 and then in textBox3 and keep textBox1
empty,then on saving the editor, an error message is shown that "textBox1
cannot be empty".
On clicking the OK button of the error message dialog box, the focus is set
to textBox3 which was last edited.
I want the focus to be set on the textBox1, ie. the textbox which shows the
error.
For this I tried using the setFocus() method but I found that the
isEnabled() property of textBox1 is returning false and thats why the focus
is not setting on the textBox1.
I also tried textBox1.setEnabled(true), but this is also not working.
Before save the state of the editor is saved in the Display and after the
save is complete the focus is returned back to the widget last edited.
Can you suggest something?]]>jay2010-02-09T12:51:59-00:00Re: Set focus problem in editor
https://www.eclipse.org/forums/index.php/mv/msg/162300/513614/#msg_513614
Setting enablement and focus while the error dialog is up should not be a
problem, the snippet below does it. Does the snippet work for you? And,
which platform and swt version are you using?
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
final Text text1 = new Text(shell, SWT.SINGLE);
final Text text2 = new Text(shell, SWT.SINGLE);
shell.pack();
shell.open();
text2.setFocus();
text1.setEnabled(false);
display.timerExec(2222, new Runnable() {
public void run() {
final Shell child = new Shell(shell);
child.setLayout(new FillLayout());
Button button = new Button(child, SWT.PUSH);
button.setText("Push");
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
text1.setEnabled(true);
text1.setFocus();
child.dispose();
}
});
child.pack();
child.open();
while (!child.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"jay" <jaydeep.marumale@gmail.com> wrote in message
news:hkrlm2$rhb$1@build.eclipse.org...
> I have an editor which has 3 text boxes: textBox1, textBox2, textBox3.
> I enter certain values in text box2 and then in textBox3 and keep textBox1
> empty,then on saving the editor, an error message is shown that "textBox1
> cannot be empty".
> On clicking the OK button of the error message dialog box, the focus is
set
> to textBox3 which was last edited.
> I want the focus to be set on the textBox1, ie. the textbox which shows
the
> error.
> For this I tried using the setFocus() method but I found that the
> isEnabled() property of textBox1 is returning false and thats why the
focus
> is not setting on the textBox1.
> I also tried textBox1.setEnabled(true), but this is also not working.
> Before save the state of the editor is saved in the Display and after the
> save is complete the focus is returned back to the widget last edited.
>
> Can you suggest something?
>
>]]>Grant Gayed2010-02-10T12:14:10-00:00Re: Set focus problem in editor
https://www.eclipse.org/forums/index.php/mv/msg/162300/513503/#msg_513503
Vijay Raj2010-02-10T12:24:07-00:00