Results 1 to 5 of 5

Thread: auto combo box

  1. #1
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default auto combo box

    In my JAVA dekstop application i am having a problem in selecting item from the combo box.
    Suppose i have 10 items in the combo box and around 5 of them starting with alphabet 'A'.Now when i select the combo box and type 'A' i want all the items starting with the alphabet 'A' to be displayed in the combo box. Similarly suppose the next alphabet i type after 'A' is 'D',then i want all the items having the initials 'AD' to be displayed in the combo box and so on.

    anyone can please suggest me some code to get the desired result.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: auto combo box

    What have you tried? Where are you stuck? Sounds like a job for a KeyListener or Key Bindings to me.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: auto combo box

    Edit: Misread your question. As said above, KeyListener is probably the way to go.

    I would be careful though. If you are going to be dynamically adding/removing elements in your JComboBox as the user types, you might want to put a catch in there, such that if they press a Backspace key, the list goes back to all the original items.

    That way if your JComboBox has, for example, elements "a","b","c", and the user types a 'b', the JComboBox is dwindled down to one choice. How would they then get back to all the original items if they type the wrong key? Either that or a reset button, just a thought.
    Last edited by sehudson; 03-27-2012 at 08:24 PM.

  4. #4
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: auto combo box

    Quote Originally Posted by KevinWorkman View Post
    What have you tried? Where are you stuck? Sounds like a job for a KeyListener or Key Bindings to me.
    a, adding the item in combo box from data base by jcombobox.additem(rs.getstring(1));
    and after that if wants a particular name so typing the first letter of that name it should show aal the names strating with that name. not getting any clue.
    if there is any alternative then pls suggest me i have very less time.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: auto combo box

    Search the net for Java autocomplete textfield (or similar terms). Your requirement is very similar to that.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to make Combo box Auto Complete/Type Ahead?
    By sandeep43 in forum New To Java
    Replies: 3
    Last Post: 09-06-2011, 07:49 AM
  2. dynamically populate the city combo box based on the values of state combo +ajax+jsp
    By sandy1000 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-29-2010, 10:00 AM
  3. Auto contrast and auto brightness
    By oxxxis in forum Java 2D
    Replies: 0
    Last Post: 01-21-2010, 08:32 PM
  4. creation of one combo box form another combo box
    By er.tyagigaurav in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-09-2008, 03:14 PM
  5. Auto-complete/Auto-fix for custom statement
    By dark_cybernetics in forum Eclipse
    Replies: 0
    Last Post: 08-19-2008, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •