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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:38:03+00:00 2026-06-10T22:38:03+00:00

I am learning java swing. There is an editable JComboBox for selecting different depths

  • 0

I am learning java swing. There is an editable JComboBox for selecting different depths of water and a JTextField to accept mobile number. My question is how can I restrict the user to enter only digits in these two fields and also, how to limit the maximum number of character inputs like not more than 10 for the mobile number? Are methods available for these requirements or I need to define them of my own?
Thanks in advance for your help.

  • 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-06-10T22:38:05+00:00Added an answer on June 10, 2026 at 10:38 pm

    Use a JFormattedTextField something like:

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
    
            @Override
            public void run() {
                JFrame frame = new JFrame("JFormattedTextField Example");
                MaskFormatter fmt = null;
    
                // A phone number 10 digits 
                try {
                    fmt = new MaskFormatter("(###)-###-####");//brackets () are optional just there for my pref
                    fmt.setPlaceholderCharacter('*');//set place holder for the empty digits of the number
    
                } catch (java.text.ParseException e) {
                }
    
                JFormattedTextField tft1 = new JFormattedTextField(fmt);
    
                frame.add(tft1);
    
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.pack();
                frame.setVisible(true);
            }
        });
    }
    

    This automatically has the properties you want it will only accept digits in a specified format
    Have a look at the docs too for more info: JFormattedTextField

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

Sidebar

Related Questions

I am learning Java with Swing and I have some problems with using JTextField
Hi I have been learning Java Swing for creating a chess game to practice
I'm learning Java right now but I'm wondering if there is a hierarchy of
I'm learning event-driven programming by Java now, but most materials are about swing. I
I am learning Java using Eclipse - started a project with javax.swing and could
I am new to Java, started learning swing and have a problem with resizing
I am learning java swing from the Dive Log tutorial. An object has been
I am learning java swing. The code below is a catch block which handles
I am learning Java Swing and I appended a menuBar to the frame. By
I'm learning Java from a webdev background. I've been using some HTML inside Swing

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.