无法在GWT应用程序中设置TextBox的焦点 [英] not able to set focus on TextBox in a GWT app

查看:148
本文介绍了无法在GWT应用程序中设置TextBox的焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不应该导致我那么多的痛苦,但它是。这是一个非常奇怪的问题。在GWT应用程序中,我有两个.java文件,login.java和application.java。
在login.java中,我创建了一个用户登录页面,如果用户名和密码被验证,用户登录到应用程序,并且application.java从这里获取。



现在在应用程序中。 java的onModuleLoad()这是我如何开始登录页面。

  public void onModuleLoad(){
登录login = new Login();
login.textBoxUsername.setFocus(true);
RootLayoutPanel.get()。add(login);}

因为当页面加载时无法将焦点放在用户名文本框上的小问题。我尝试了一些我能想到的东西。但是焦点没有在TextBox上设置。如果有人可以提出解决方案,请做。



解决方案:(如果它可以帮助任何人面对相同的问题)

 最终登录login = new Login(); 
Scheduler.get()。scheduleDeferred(new ScheduledCommand(){
public void execute(){
login.textBoxUsername.setFocus(true);
}
} );

RootLayoutPanel.get()。add(login);


解决方案

尝试使用 Scheduler.scheduleDeferred()

  public void onModuleLoad(){
Login login = new Login();
Scheduler.get()。scheduleDeferred(new Scheduler.ScheduledCommand(){
public void execute(){
login.textBoxUsername.setFocus(true);
}
});
RootLayoutPanel.get()。add(login);
}

更新: answer已更新为使用 Scheduler.get()。scheduleDeferred()而不是 DeferredCommand ,不推荐使用。


This should not be causing me so much pain but it is. It is a very weird problem. In a GWT application, I have two .java files, login.java and application.java. In login.java, I'm creating a user login page where if the username and password is verified the user is logged into the application and application.java takes from here.

Now in application. java's onModuleLoad() this is how i'm starting with a login page.

public void onModuleLoad() {
  Login login = new Login();
  login.textBoxUsername.setFocus(true);
  RootLayoutPanel.get().add(login);}

This works great, except for the tiny problem of not being able to set focus on the username TextBox when the page loads. I have tried evrything I can think of. But the focus just doesn't get set on the TextBox. If anyone can suggest a solution, please do. Your help is greatly appreciated.

Solution: (In case it helps anyone facing the same issue)

final Login login = new Login();
  Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        public void execute () {
            login.textBoxUsername.setFocus(true);
        }
   });

  RootLayoutPanel.get().add(login);

解决方案

Try using Scheduler.scheduleDeferred():

public void onModuleLoad() {
    Login login = new Login();
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand () {
        public void execute () {
            login.textBoxUsername.setFocus(true);
        }
    });
    RootLayoutPanel.get().add(login);       
}

Update: answer updated to use Scheduler.get().scheduleDeferred() instead of DeferredCommand, which is deprecated.

这篇关于无法在GWT应用程序中设置TextBox的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆