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

  • SEARCH
  • Home
  • 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 3840536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:32:28+00:00 2026-05-19T15:32:28+00:00

I want to cancel a keypress event for a long textbox so that the

  • 0

I want to cancel a keypress event for a long textbox so that the character newly pressed by the user is not entered in the textbox

longBox_1.addKeyPressHandler(new KeyPressHandler(){
    @Override
    public void onKeyPress(KeyPressEvent event) {
        String Valid="1234567890";
        if (!Valid.contains(String.valueOf(event.getCharCode()))) {
            // the code to cancel the event to be placed here
        }
    }
});
  • 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-19T15:32:28+00:00Added an answer on May 19, 2026 at 3:32 pm

    If your longBox_1 is a private member of your class, or a final var, the code to cancel the event is :

    longBox_1.cancelKey();
    

    Otherwise you can cast the source of the event, if you are sure it correspond to the TextBox :

    ((TextBox)event.getSource()).cancelKey();
    

    Here is the doc for cancelKey :

    If a keyboard event is currently being
    handled on this text box, calling this
    method will suppress it. This allows
    listeners to easily filter keyboard
    input

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

Sidebar

Related Questions

I want to cancel an event from within that function scope. Eg. I pressed
I want to inject a confirmation dialog to allow the user to cancel the
I want to create a PDF that will bring up a typical OK/Cancel alert
I've got a navigation app. I want to get position information that may not
I want to capture the TAB keypress, cancel the default action and call my
I want to cancel a JDBC call if it's taking too long to respond
On some condition I want to cancel onmousemove event when mouse goes down, for
I want to cancel the Context Menu Opened Event of a TreeViewItem private void
I have VS 2010 and want to cancel the form closing event via a
I want to cancel this operation if the user selects a specific item because

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.