Whenever I see problems like this I try deferring the focus and/or
listener registration from the event which creates a new widget like
this. The Tree implementation includes some fun internals which change
focus on things to ensure visibility and handle keyboard input.
Example:
public void onClick(Widget w) {
DeferredCommand.addCommand(new Command() {
public void execute() {
createMyWidget();
}
});
}
On Jan 8, 10:08 am, "David Durham" <[email protected]> wrote:
> Hi all,
>
> I've got an issue with a focus listener on a TextBox in a TreeItem. I
> want to take action when the textbox loses focus. The code I have
> works perfectly in hosted mode on Linux, but does not work in Firefox
> after compile/browse. Here's the code:
>
> private void newTreeTextBox(final DynamicTreeItem item, final
> FieldGroup group) {
> final String originalText = item.getText();
> final TextBox box = new TextBox();
> box.setText(originalText);
> item.setWidget(box);
> box.selectAll();
> box.setFocus(true);
> box.addKeyboardListener(new KeyboardListenerAdapter() {
> public void onKeyPress(Widget sender, char keyCode, int
> modifiers) {
> if (keyCode == KEY_ENTER) {
> setItemText(item, originalText, box.getText(), group);
> } else if (keyCode == KEY_ESCAPE) {
> setItemText(item, originalText, null, group);
> }
> }
> });
> box.addFocusListener(new FocusListenerAdapter() {
> public void onLostFocus(Widget sender) {
> Window.alert("lost focus");
> setItemText(item, originalText, box.getText(), group);
> }
> });
> }
>
> I've got a debug alert in my onLostFocus method. What happens is I
> click on an item, it's replaced with a textbox with text selected. I
> hit press any key, and the lostFocus event is fired. Any ideas?
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---