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 7679005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:46:37+00:00 2026-05-31T17:46:37+00:00

In my application four TextArea is there and I want to enter only four

  • 0

In my application four TextArea is there and I want to enter only four character in one Text area and cursor automatically move to next TestArea. Again when I enter four character in this TextArea then again cursor automatically move to next TextArea.

Example: At the time of installing Window XP it want “Key” and there are four section when you enter four character in first section then cursor automatically move to the next section.

Same thing I want in my application.

For this first of all I add CustomizedTextFields.jar and then created four IntegerField:

private IntegerField text1;
private IntegerField text2;
private IntegerField text3;
private IntegerField text4;

after this I show all these IntegerField on my frame.

Now I tried this code to send cursor to the next field but it’s not working:

text1.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                    int a2 = text1.getText().length();
                    if (a2 == 3) {
                        text2.getCursor();
                    }
            }

            @Override
            public void keyReleased(KeyEvent e) {
            }

            @Override
            public void keyPressed(KeyEvent e) {
            }
        });
  • 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-31T17:46:38+00:00Added an answer on May 31, 2026 at 5:46 pm

    interesting enough question to try improving my shadowy knowledge of the text package 🙂

    There are two separate requirements here

    • restrict the lenght of the text: that’s done with a DocumentFilter as @mKorbel already noted
    • automatically transferFocus to the next component after the max length is reached: turns out that can be done with a NavigationFilter

    in code:

    JComponent panel = new JPanel();
    final int maxSize = 3;
    for (int i = 0; i < 4; i++) {
        final JTextField field = new JTextField(5);
        NavigationFilter filter = new NavigationFilter() {
    
            @Override
            public void setDot(FilterBypass fb, int dot, Bias bias) {
                if (dot >= maxSize) {
                    fb.setDot(0, bias);
                    field.transferFocus();
                    return;
                }
                fb.setDot(dot, bias);
            }
    
            @Override
            public void moveDot(FilterBypass fb, int dot, Bias bias) {
                if (dot >= maxSize) { 
                    fb.setDot(0, bias);
                    field.transferFocus();
                    return;
                }
                fb.moveDot(dot, bias);
            }
    
        };
        field.setNavigationFilter(filter);
        ((AbstractDocument) field.getDocument()).setDocumentFilter(new DocumentSizeFilter(maxSize));
        panel.add(field);
    }
    

    The documentFilter is the one from the Swing Tutorial

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

Sidebar

Related Questions

In my application - there are four buttons named as follows: Top - left
I've got four activities which the application cycles through. The first one fetches huge
i am working on application in which i want to frequently change four imageviews
I have implement one application in which four image button and on image button
I am using windows application and I have four combo boxes(comboeventname,combosendtype,comboType,comboschedule) in that form....
I have a web application that synchronizes with a central database four times per
I have a four WAR files which are modules of application. How I can
I have an android application. I have four screens and each screen contains a
I have a C# application using WPF consisting of a single Window holding four
I have collectionView in my wpf application. For sorting purpose, I add four SortDescriptions

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.