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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:56:29+00:00 2026-05-29T03:56:29+00:00

I created a class comboauto for to get an itemnames from mysql database in

  • 0

I created a class comboauto for to get an itemnames from mysql database in combo box. I did an auto suggestion in jcombobox assigned jtextfield as default, to get text in jtextfield. when i am typing a text U(it should auto suggest and give both lowercase and uppercase u values) in jcombobox. I am not getting both the case value when typing into a text. Please help me, what method i am supposed to use here.

This is the code i used
public class comboauto extends javax.swing.JFrame{
             Vector Tmpv1=new Vector();
             Statement TmpSqlStmnt;
             ResultSet TmpSqlRs;
             Connection Tmpcon;
             String TmpCateId;
             JTextField Txt01;
             TreeMap TmpMap=new TreeMap();

        public comboauto() {
               initComponents();
        }

        public void FRM_CBX_AUTOSUGGEST() {
               Txt01=(JTextField)Cbx01.getEditor().getEditorComponent();
                Txt01.addKeyListener(new KeyAdapter() {
               public void keyTyped(KeyEvent e)
                {
                       EventQueue.invokeLater(new Runnable()
                     {
                           public void run(){
                                  String Tmptext =Txt01.getText();
                                  if(Tmptext.length()==0)
                                   {
                                        Cbx01.hidePopup();
                                        setModel(new DefaultComboBoxModel(Tmpv1), "");
                                     }
                                     else{
                                       DefaultComboBoxModel m = getSuggestedModel(Tmpv1, Tmptext);
                                       if(m.getSize()==0 ) {
                                       Cbx01.hidePopup();
                                         }
                                        else{
                                                  setModel(m, Tmptext);
                                                 Cbx01.showPopup();

                                             }
                                         }
                                 }
                             });
                   }                        
            });
             try{
                    Class.forName("com.mysql.jdbc.Driver");
                    Tmpcon =DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root","root");
                    TmpSqlStmnt=Tmpcon.createStatement();
                    TmpSqlRs=TmpSqlStmnt.executeQuery ("SELECT CateId,CateName FROM Cust_Masterrecord ORDER BY CateName");
                    System.out.println("DB Connected");
                    TmpSqlRs.first();
                    do {
                            String TmpName=TmpSqlRs.getString("CateName");
                            Cbx01.setSelectedIndex(-1);
                            Cbx01.addItem(TmpName);
                            int TmpCateId=TmpSqlRs.getInt("CateId");
                            Tmpv1.addElement(TmpSqlRs.getString("CateName"));
                            TmpMap.put(TmpName, TmpCateId);

                           Cbx01.addItemListener(new ItemListener()
                            {
                            public void itemStateChanged(ItemEvent e) {
                                   if (e.getStateChange() == e.SELECTED) {

                                       Lbl01.setText(TmpMap.get(Cbx01.getSelectedItem()).toString());
                                  }
                                }
                            });
                    }while(TmpSqlRs.next());
    }catch(Exception e){
    System.out.println(e);
  }
  }
private boolean hide_flag = false;
       private void setModel(DefaultComboBoxModel mdl, String str)
       {
        Cbx01.setModel(mdl);
        Cbx01.setSelectedIndex(-1);
        Txt01.setText(str);
       }
private static DefaultComboBoxModel getSuggestedModel(java.util.List<String> list, String text) {
        DefaultComboBoxModel m = new DefaultComboBoxModel();

        for(String s: list) {
            if(s.startsWith(text)) m.addElement(s);
        }
        return m;
    }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               comboauto Tmpobj1= new comboauto();
               Tmpobj1.FRM_CBX_AUTOSUGGEST();
               Tmpobj1.setVisible(true);


            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JComboBox Cbx01;
    private javax.swing.JLabel Lbl01;
    // End of variables declaration                   

}
  • 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-29T03:56:30+00:00Added an answer on May 29, 2026 at 3:56 am

    Use String.toUpperCase in you getSuggestedModel method. (Uppercase both strings. Lowercase also works.)

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

Sidebar

Related Questions

I created class: class StorageBase { public Queue<Slices> Slices {get;set;} } and wpf custom
Is it best to use a pre created class / api for database interaction
I created class ChImage from UIImage @interface ChImage : UIImage { @public int ChannelId;
I created class inherited from DataTable. I want to Expose the items like Name
I've created class that takes Exception type in constructor private readonly Exception _exception; public
I am created class diagram in asp.net mvc. I drag and droped some of
I created a class that's something like this: public class MovieTheaterList { public DateTime
I created a class CMyClass whose CTor takes a UCHAR as argument. That argument
I created a class that handles serial port asynchronously. I use it to communicate
I created a class Entry to handle Dictionary entries, but in my main(), I

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.