Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Set focus problem in editor
Set focus problem in editor [message #513228] Tue, 09 February 2010 12:51 Go to next message
jay is currently offline jayFriend
Messages: 5
Registered: July 2009
Junior Member
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?
Re: Set focus problem in editor [message #513503 is a reply to message #513228] Wed, 10 February 2010 12:24 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
try setting the focus before opening the dialog...

---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Set focus problem in editor [message #513614 is a reply to message #513228] Wed, 10 February 2010 12:14 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Did you disable textBox1? This should not just be happening for free.

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?
>
>
Previous Topic:DragSource and Composite
Next Topic:Adding a button to show preferences dialog in toolbar
Goto Forum:
  


Current Time: Thu Apr 25 02:19:07 GMT 2024

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

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

Back to the top