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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:54:31+00:00 2026-05-25T09:54:31+00:00

I want to create an auto-complete program in java which should provide a list

  • 0

I want to create an auto-complete program in java which should provide a list of suggestions instantly when the user types a character/String inside a JTextfield. The problem is that I am confused on how to do it.

Could somebody provide an idea or a sample on the said problem?

  • 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-25T09:54:31+00:00Added an answer on May 25, 2026 at 9:54 am

    1) you have to sort your array before use for better performance…

    2) as I mentioned you have to take these two clasess

    3) don’t forget set initial value for better and nicest work with these Components

    simple output

    enter image description here

    from code

    import java.awt.*;
    import java.util.ArrayList;
    import javax.swing.*;
    
    public class AutoCompleteTextField {
    
        private JFrame frame;
        private ArrayList<String> listSomeString = new ArrayList<String>();
        private Java2sAutoTextField someTextField = new Java2sAutoTextField(listSomeString);
        private ArrayList<String> listSomeAnotherString = new ArrayList<String>();
        private Java2sAutoComboBox someComboBox = new Java2sAutoComboBox(listSomeAnotherString);
    
        public AutoCompleteTextField() {
            listSomeString.add("-");
            listSomeString.add("Snowboarding");
            listSomeString.add("Rowing");
            listSomeString.add("Knitting");
            listSomeString.add("Speed reading");
            listSomeString.add("Pool");
            listSomeString.add("None of the above");
    //
            listSomeAnotherString.add("-");
            listSomeAnotherString.add("XxxZxx Snowboarding");
            listSomeAnotherString.add("AaaBbb Rowing");
            listSomeAnotherString.add("CccDdd Knitting");
            listSomeAnotherString.add("Eee Fff Speed reading");
            listSomeAnotherString.add("Eee Fff Pool");
            listSomeAnotherString.add("Eee Fff None of the above");
    //
            someTextField.setFont(new Font("Serif", Font.BOLD, 16));
            someTextField.setForeground(Color.black);
            someTextField.setBackground(Color.orange);
            someTextField.setName("someTextField");
            someTextField.setDataList(listSomeString);
    //
            someComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            someComboBox.setFont(new Font("Serif", Font.BOLD, 16));
            someComboBox.setForeground(Color.black);
            someComboBox.setBackground(Color.YELLOW);
            someComboBox.getEditor().selectAll();
            someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW);
            ((JTextField) someComboBox.getEditor().getEditorComponent()).setDisabledTextColor(Color.black);
            someComboBox.setName("someComboBox");
            someComboBox.setDataList(listSomeAnotherString);
    //
            frame = new JFrame();
            frame.setLayout(new GridLayout(0, 1, 10, 10));
            frame.add(someTextField);
            frame.add(someComboBox);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocation(100, 100);
            frame.pack();
            frame.setVisible(true);
    //
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    someTextField.setText("-");
                    someComboBox.getEditor().setItem(0);
                    someComboBox.getEditor().selectAll();
                    someTextField.grabFocus();
                    someTextField.requestFocus();
                    someTextField.setText(someTextField.getText());
                    someTextField.selectAll();
                }
            });
    
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    AutoCompleteTextField aCTF = new AutoCompleteTextField();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an auto complete program and I am using JComboBox for
I want create a excel with Apache POI in java and I must insert
I want to create a Java application bundle for Mac without using Mac. According
I want to create an allocator which provides memory with the following attributes: cannot
I'm trying to create a custom UserControl that will mimic auto-complete as it works
I want to make an auto complete system using Jquery from the yahoo pipes
I want create a drop shadow around the canvas component in flex. Technically speaking
i want create image animation , i have 50 images with png format now
I want to create a client side mail creator web page. I know the
I want to create a function that performs a function passed by parameter on

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.