Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6137053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:40:44+00:00 2026-05-23T17:40:44+00:00

I have a problem with setFocus(). Why it does not work on textBox? This

  • 0

I have a problem with setFocus(). Why it does not work on textBox?

This is my code:

package com.test.test1;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.user.client.ui.FocusWidget;

public class Logowanie extends Composite {
    public Logowanie(final Spr spr) {

        VerticalPanel verticalPanel = new VerticalPanel();
        initWidget(verticalPanel);

        Label lblZalogujSi = new Label("Zaloguj si\u0119");
        lblZalogujSi.setStyleName("title");
        verticalPanel.add(lblZalogujSi);

        FlexTable flexTable = new FlexTable();
        verticalPanel.add(flexTable);

        Label lblLogin = new Label("Login:");
        flexTable.setWidget(0, 0, lblLogin);

        TextBox textBox = new TextBox();
        textBox.setFocus(true);

        flexTable.setWidget(0, 1, textBox);

        Label lblHaso = new Label("Has\u0142o:");
        flexTable.setWidget(1, 0, lblHaso);

        TextBox textBox_1 = new TextBox();
        flexTable.setWidget(1, 1, textBox_1);

        CheckBox chckbxZapamitajMnie = new CheckBox("Zapami\u0119taj mnie na tym komputerze");
        flexTable.setWidget(2, 1, chckbxZapamitajMnie);

        Button btnZaloguj = new Button("Zaloguj");

        KeyPressHandler kph = new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if (event.getCharCode() == KeyCodes.KEY_ENTER){
                    spr.login();
                }
            }
        };

        textBox.addKeyPressHandler(kph);
        textBox_1.addKeyPressHandler(kph);

        btnZaloguj.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                spr.login();
            }
        });
        flexTable.setWidget(3, 1, btnZaloguj);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:40:45+00:00Added an answer on May 23, 2026 at 5:40 pm

    The problem with this is that the textbox needs to be drawn in the browser before you can run setFocus() on it. This is the latest what gwt suggests –

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        public void execute () {
            textBox.setFocus(true);
        }
       });
    

    Use this code instead of plain calling setFocus(true);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have only seen code solutions to this problem. I am looking for a
I have problem with my code. I don't know what am I doing wrong.
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have problem with this query DECLARE @INPUT INT SET @INPUT = 12345 ;
I have problem with pointers. This is working fine - int main(void){ char *w;
i have a TextBox control on my masterpage <asp:TextBox ID=txtSubject runat=server Width=280px CssClass=formtxt onblur=if(this.value=='')
I have problem getting the dropdown menu to work using Twitter's Bootstrap. Here's my
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.