JComboBox with type-ahead capabilities?

Hi, guys:
I have a JComboBox with a list of string items. Since the list is very long (with several hundred of items), I would like to implement someting like
the following so that use does not have to scroll down the list to search for an item: when user types the starting letter of an item, it should locate the first item starting with this letter. IE address bar has this kind of type-ahead capability
I am wondering how I can do the similar thing using Swing JComboBox?
regards,

Thanks for your sample, it works.
Here is the "old code" I am talking about. I slightly modified it and add a main method. It looks fine, but it just does not work. I really have no clue why this one just does not work:
import java.awt.event.KeyListener;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class SelectableComboBox
    extends JComboBox
    protected boolean required;
    protected JLabel fieldLabel;
    public SelectableComboBox()
        super();
    public SelectableComboBox( final boolean required )
        super();
        this.required = required;
    public SelectableComboBox( final ComboBoxModel model )
        super( model );
    public SelectableComboBox( final Object[] objects )
        super( objects );
    public SelectableComboBox( final Vector v )
        super( v );
    public void setEnabled( final boolean b )
        super.setEnabled( b );
        if( this.fieldLabel != null )
            this.fieldLabel.setEnabled( b );
    public JLabel getLabel()
        return this.fieldLabel;
    public void setLabel( final JLabel l )
        this.fieldLabel = l;
    public JLabel createLabel( final String s )
        this.fieldLabel = new JLabel( s );
        return this.fieldLabel;
    public boolean isEquals( final String s )
        if( this.fieldLabel != null && this.fieldLabel.getText() != null
                && s != null )
            return s.equals( this.fieldLabel.getText() );
        return false;
    public String toString()
        if( this.fieldLabel != null && this.fieldLabel.getText() != null
                && this.fieldLabel.getText().length() > 0 )
            return this.fieldLabel.getText();
        return super.toString();
    public void setRequired( final boolean req )
        this.required = req;
    public boolean isRequired()
        return this.required;
    public JTextField getTextField()
        int total = getComponentCount();
        JTextField field = null;
        for( int i = 0; i < total; i++ )
            if( getComponent( i ) instanceof JTextField )
                field = (JTextField) getComponent( i );
                break;
        return field;
    public JButton getButton()
        int total = getComponentCount();
        JButton button = null;
        for( int i = 0; i < total; i++ )
            if( getComponent( i ) instanceof JButton )
                button = (JButton) getComponent( i );
                break;
        return button;
    public void addKeyListener( final KeyListener l )
        JTextField field = getTextField();
        if( field != null )
            field.addKeyListener( l );
    public void removeKeyListener( final KeyListener l )
        JTextField field = getTextField();
        if( field != null )
            field.removeKeyListener( l );
    public static void main( final String[] args )
        JFrame fr = new JFrame();
        fr.setSize(150,75);
          fr.setLocation(400,300);
          fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JPanel jp = new JPanel();
          SelectableComboBox cb = new SelectableComboBox();
        cb.addItem( "Abc" );
        cb.addItem( "cbs" );
        cb.addItem( "nbc" );
        cb.addItem( "fox" );
        cb.addItem( "wb" );
        cb.addItem( "ycc" );
          jp.add(cb);
          fr.getContentPane().add(jp);
        fr.pack();
        fr.setVisible( true );
}Appreciate your help.

Similar Messages

  • Dynamic parameter with 'type-ahead' capability

    Hi,
    How do I create a dynamic parameter that will return a drop down list of over 11,000 records in alphabetic order that I can then select the value I want by starting to type in the value.  For example, in a list of cities of the world I want to select 'London' so I type in an 'L' and the list moves to the first city starting with an 'L', I then type an 'o' and the list goes to 'Lo' etc.
    At the moment only 30 values appear in the drop-down list and I can only enter the first letter.
    I want to use this value as the parent for a cascading parameter.
    Thanks, Colin

    The dynamic parameter does not have the functionality to 'type-ahead' and go to specific values in the list in that manner. The most you can do is go to values that start with a specific letter and scroll through them. This behavior is occurring by design.
    By default, Crystal Reports will only return the first 1000 unique values for a dynamic parameter. This can be changed through a registry entry.
    For information on changing the values retrieved for the dynamic parameter, you can refer to the following Business Objects Note.
    - Go to this link
    https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_ossnotes&query=&adv=true
    - Search for the Note: 1218588
    When using a dynamic parameter, the limit will be a combination of all the values return at each level to reach the total number of records returned. Also the more records that you return to the dynamic parameter, the longer it will take to retrieve the data from the database.

  • Problem with type ahead, maybe known as keyboard buffer or keyboard buffering

    Hi, I'm new to Lightroom and am halfway through Martin Evening's excellent book, but there's a problem I have which I can't find an answer to anywhere so far.
    I work on an older PC that has three screens.  My problem is if I have LR on one screen and type into an application in another screen, or rather think I'm typing into the other application but actually the LR screen is still active, then LR basically goes nuts as it attempts to carry out what is in effect a random series of keyboard shortcuts.  I have to wait for LR to finish jumping about and then so a long series of undo's and hope that one of the shortcuts wasn't a delete.
    It's occurred to me within LR when I've been typing into the keywords box and predded Enter twice by mistake to confirm an auto complete suggestion by LR and so subsequently exited the keywords box causing LR to interpret all my following keyword letters as commands.
    Is there any way to change this? To my mind there shouldn't be any need for LR to read from the keyboard buffer at all.  Is there any way to turn off keyboard shortcuts either all of them or selectively?

    Biganon,
    If you are willing to experiment, you could try the following simple xorg.conf:
    Section "Device"
    Identifier "Configured Video Device"
    Driver "nvidia"
    EndSection
    Section "Screen"
    Identifier "Default Screen"
    Device "Configured Video Device"
    DefaultDepth 24
    EndSection
    This minimal xorg.conf is only needed because xorg must be told to use the nvidia drivers.
    It should figure everything else by itself.
    For the Keyboard and mouse handling, install xf86-input-evdev, if not already there.
    Start hal from the daemons Line in /etc/rc.conf:
    DAEMONS=(syslog-ng network netfs !dbus hal ....
    For the Keyboard layout, copy the file:
    /usr/share/hal/fdi/policy/10osvendor/10-keymap.fdi
    to
    /etc/hal/fdi/policy/10-keymap.fdi
    and edit this copy as follows:
    <merge key="input.xkb.layout" type="string">ch</merge>
    <merge key="input.xkb.variant" type="string">fr</merge>
    I don't particularly appreciate this fdi thing, but, from experience, letting a particular
    Desktop/Window Manager manage the keyboard layout is even worse.
    Further info at:
    http://wiki.archlinux.org/index.php/Xor … otplugging
    Needless to say, if you try this, backup your original xorg.conf.
    Mektub

  • Looking for a database application with report-writing capabilities for my iMac.

    Does anyone know of an iMac-compatible database application (small business type) with report-writing capabilities?

    That's easy, you are looking for FileMaker Pro. You can find it at:
    http://www.filemaker.com

  • How to implement type-ahead for search

    Hi there,
    I would like to have type-ahead for my endeca. e.g. if user clicks on search box and type"g", it should show all items starts with g.
    How can I do that? I have only three dimensions : PRIRCERANGE, category and flex. And I have 3 properties: description, color, price, uom, sku etc.

    Endeca exposes webservice that can be accessed by xquery library provided by endeca. You can write your own xquery module to fetch dimension query result, format and use as a output to type-ahead.
    Refer below xquery guide to get more details about developing
    your own xquery module,
    http://docs.oracle.com/cd/E28910_01/MDEX.622/pdf/XQueryDevGuide.pdf
    HTH
    -Pravin

  • How can I restore "type ahead" Search suggestions?

    Back in the good old days of Safari 3 (and 4?) it had a useful trick of auto-completing phrases as you started typing in the Google Search field. It stopped working in Safari 5, so I was directed to Glims for Safari, which worked great.
    Up until last week, although the Links part of Glims didn't work, the Search Words (i.e. type ahead) did work so I was happy enough. Now it's stopped. I download the latest Glims and now I have the Links working, but not the type ahead Search Words!
    In Safari I've changed my New Tab default page from Top Sites to Google UK Home page instead. This loads much quicker than Top Sites and the cursor is in the Search field. Typing anything brings "type ahead search suggestions".
    Is this my only option? Anyone know why Glims should suddenly stop doing what it used to?

    For an issue with Glims, better to ask the developers of the software.
    You can report a bug here >  http://www.machangout.com
    If you are a Facebook user, you can Like Glims then ask questions directly on their news feed. They will respond.
    For Safari, make sure:  Prevent search engine from providing suggestions is not selected in Preferences > Privacy
    And try this for Safari...
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type of copy/paste:   ~/Library/Caches/com.apple.Safari
    Click Go then move the Cache.db file from the com.apple.Safari folder to the Trash.
    Quit and relaunch Safari to test.
    edited by:  cs

  • Implementation of type-ahead functionality in Endeca JSP Ref application

    Hi all,
    I am trying to implement the type-ahead functionality in Endeca jsp reference application which Oracle is shipping with it's products. The type-ahead functionality is not present by default. Can anyone help me to implement the same thing or provide sample code/strategy to achieve the desired results ?
    Basically typeahead functionality is present in Endeca Information's quick start's search box (EID) but not it JSP reference application .
    Waiting for the replies...
    Regards,
    Hoque

    Type-ahead functionality can mean different things and be implemented in different ways. It is usually based on what behavior your user-space would benefit from.
    In the commerce space, one popular use-case is to return Category matches based on what a user has started typing. Within Endeca, this boils down to doing a dimension search and having the Category dimension enabled for dimension search. If a user starts typing "cam", the type-ahead would then recommend:
    Category: Cameras
    You can match on multiple dimensions though, so long as they are enabled for dimension search. For example, if a user starts typing "ca", the type-ahead could return:
    Category: Cameras
    Brand: Canon
    Furthermore, this behavior can be extended by enabling Compound Dimension Search. Compound Dimension Search is enabled via a flag on the dgidx process and on your ENEQuery. It provides the following behavior. If a user searches for "canon cam", it would suggest:
    Category: Cameras + Brand: Canon
    Clicking on the type-ahead would return the intersection of Category = Cameras and Brand = Canon, eliminating a click if the user is after Canon brand Cameras.
    With regards to implementation, it basically boils down to an AJAX call to a service/URL that responds with dimension search results. Then populate an empty &lt;div&gt; with links.
    Other scenarios involve returning Product/Record matches instead of Dimension matches.
    Edited by: gose on Sep 11, 2012 8:31 AM

  • Type ahead in drop down lists

    Hi, I would like to be able to type ahead in drop down lists. E.g. with an alphabetical drop down list having
    Scott
    Sean
    Soo
    Steven
    I would like to be able to position within that drop down list by typing e.g. st and land upon steven, however when I key in st, I find myself at the top of the entries in the drop down list starting with t.
    Any ideas? Something I overlooked?
    Best regards, Jesper

    Jesper,
    I admit that I don't fully understand how it all works, but I'll explain the general steps I took to get it working. Hopefully some of the smart people here can show us a better way to do it.
    I don't think that I should post the actual javascript file because the first line of it says:
    "// Copyright 2004 and onwards Google Inc."
    But, you can get the original version of it here: http://www.google.com/ac.js
    If you save it and a copy of the page that calls it on your local web server, you can play around with it.
    It looks like a real mess. This guy has dissected it: http://serversideguy.blogspot.com/2004/12/google-suggest-dissected.html
    From all that, you can see that the end result is that the script calls a URL like this, with your query at the end:
    http://www.google.com/complete/search?hl=en&js=true&qu=transparent%20aluminu
    Which returns a result like this:
    sendRPCDone(frameElement, "transparent aluminu", new Array("transparent aluminum", "transparent aluminum 3m"), new Array("426,000 results", "31,900 results"), new Array(""));
    The script can be edited to call any URL. I changed it to call a stored procedure on my HTML DB web server. The changes were:
    Line 3: Change pn="search" to pn="schema.package.procedureName"
    Line 14: Change else E="/complete/" to E="/pls/htmldb/" (The Location entry set in your Marvel.conf)
    You then need to create a stored procedure that will be called from Line 3.
    It needs to have 3 varchar2 parameters called qu, hl, and js. The first one is the query string. I didn't use the other two.
    It needs to return a message like the script is expecting - with the results concatenated in comma-separated arrays. Here is a simple example:
    create procedure INCSEARCH(qu varchar2, hl varchar2, js varchar2) as
    l_List1 varchar2(4000);
    l_Query varchar2(255);
    l_separator varchar2(10) default '';
    begin
    l_Query := qu || '%';
    for x in (select Last_Name from hr.Employees where Upper(Last_Name) like Upper(l_Query) order by 1)
    loop
    l_list1 := l_List1 || l_separator || '"' || x.Last_Name || '"';
    l_separator := ',';
    end loop;
    owa_util.mime_header('text/html', false);
    owa_util.http_header_close;
    htp.p('sendRPCDone(frameElement, "'|| qu ||'", new Array(' || l_List1 || '), new Array(' || l_List1 || '), new Array(""));');
    end;
    Grant Execute on INCSEARCH to Public;
    The last step is to hook it into HTML DB. Examining the Google page shows that they run a script called InstallDC to hook the script to a form field.
    In the Footer section of the Page Attributes of my page, I added this:
    <SCRIPT src="/ac.js"></SCRIPT>
    <SCRIPT>InstallAC(document.wwv_flow,document.wwv_flow.p_t03,document.wwv_flow.p_t03,"dc_htmldb.incsearch","en");</SCRIPT>
    Where p_t03 is the name of the text field I want it attached to, and "dc_htmldb.incs.incsearch" is my stored procedure.
    Those are the basic steps. Does anyone have a cleaner approach?

  • Type-ahead like in address book?

    I'm developing a simple app that displays a list, on selection the item details are displayed. Since the list is very long, I'm looking for type-ahead capability like the address book has (e.g. on 6310i). Is this possible with MIDP?
    Thanks,
    Andi

    I did something along those lines for my own list control.
    the best idea i had was that i didn't try to guess what letter the user meant to get, but rather worked off the numeric sequence. I matched all possible combinations of letters from the number keys hit so far.
    Turned out this worked really well, you could get down to a few hits out of 2-300 within 3 or 4 keypresses.
    screenshots at:
    http://homepages.paradise.net.nz/section8/

  • How to implement Type Ahead in Endeca

    Hi
    Can anyone help us as how to implement type ahead search in Endeca ATG.
    Any documents related to it?
    Thanks

    Hi,
    The following links might help you.
    how to implement type-ahead for search
    Implementation of type-ahead functionality in Endeca JSP Ref application
    Re: Problem with endeca typeahead
    (You can even continue the hunt for the answer for this qn that forum as more Endeca experienced persons will be answering there)
    Thanks,
    Gopinath Ramasamy

  • Multi languages support of ComboBox type ahead feature

    Hi
    From Flex 3 livedocs (http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_5.html):
    In its editable state, the user can type text directly into the top of the list, or select one of the preset values from the list. In its noneditable state, as the user types a letter, the drop-down list opens and scrolls to the value that most closely matches the one being entered; matching is only performed on the first letter that the user types. 
    Flex combo-box indeed supports that type ahead for first letter - in English.
    e.g. for the combo box with the following list of items: {"apple","banana","orange"}, when the combo is focused and user is typing 'b'  -  "banana" will be selected.
    when I tried with other languages (i.e. russian) - it doesn't work...
    any ideas?
    thanks
    Itzik

    Thanks for you reply.
    how can I combine both dataProvider and List in ActionScript to a single comboBox?
    in MXML it would look like:
    <mx:ComboBox id="combo" dropdownFactory="the.custom.List.sub.class.goes.here">     <mx:dataProvider>
              <mx:Array>         
                   <mx:String>AAAAAAAA</mx:String> 
                   <mx:String>ABBBBBBB</mx:String>
              </mx:Array>
         </mx:dataProvider>
    </mx:ComboBox>
    but in ActionScript I couldn't make it work.
    someone?
    thanks
    Itzik

  • Mail.app and Type-Ahead

    Software update from 10.4.10 to 10.4.11...
    All ran smoothly, long restart was expected and completed successfully without interruption. So far, machine seems fine except for two problems, one of which relates to Mail.app....
    Used to be able to hit CMD-N in Mail.app and start typing before the new message window actually opened on the screen. Type-ahead worked fine. When the window finally opened, characters I had already typed appeared in the message and the system caught up with me.
    Now, when I do the same thing, I get an Alert Sound when the window actually opens and none of the characters I had already typed before the window opened appear in the message. Hence, no type-ahead any more since I updated to 10.4.11...
    Any help would be greatly appreciated.

    please reply with any answers to the question. Not being age to access the directory and view ppt files are some serious issues that prevents business users from using this app and device and apple software.

  • Clear type ahead buffer in VXML - Call Studio 8.5

    Hi,
    I'd like to take control of the type ahead buffer within my VXML script developed in Call Studio.
    So far the only thing I could find about it is a reference to a VXML prompt attribute, but nothing about how it can be set in Call Studio. Has someone successfully used this? If yes, can this be set within Call Studio?
    Thanks,
    Attila
    http://www.cisco.com/en/US/docs/ios/voice/vxml/developer/guide/refgde1.html#wp1049198 says:
    "cisco-typeaheadflush Attribute for <prompt>
    The default value of cisco-typeaheadflush is false. A false value means that the typeahead buffer is not flushed after the prompt plays out. If the prompt is bargeinable, the digit which barges in is not flushed.

    I've tried configuring it in the settings tab just like you had on the screenshot with both com.cisco.typeaheadflush and the cisco-typeaheadflush too.
    Unfortunately the non bargeable prompt is still skipped after a bargeable prompt having those set.
    Shall I be thinking of writing my custom Audio element for this?
    This is the generated VXML by the way:
    http://www.w3.org/2001/vxml" version="2.1" application="/CVP/Server?audium_root=true&calling_into=Barge_Test" xml:lang="en-GB">
          bargeable prompt

  • Is Type Ahead search available in OOTB CRS

    After setting up OOTB CRS, I noticed that there is a search project visible in BCC called SearchSuggestions and also type-ahead files for the different sites of CRS have got generated in the 'auxilliary data' folder under localconfig. Does this mean the code required to generate type-ahead xmls is already present in CRS ? I could not find it in the documentation. Since I am planning to implement this in my project, any pointer to the CRS code will be appreciated.

    For an issue with Glims, better to ask the developers of the software.
    You can report a bug here >  http://www.machangout.com
    If you are a Facebook user, you can Like Glims then ask questions directly on their news feed. They will respond.
    For Safari, make sure:  Prevent search engine from providing suggestions is not selected in Preferences > Privacy
    And try this for Safari...
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type of copy/paste:   ~/Library/Caches/com.apple.Safari
    Click Go then move the Cache.db file from the com.apple.Safari folder to the Trash.
    Quit and relaunch Safari to test.
    edited by:  cs

  • Endeca Type Ahead Search

    Hi,
      We are working on ATG 10.2 with Endeca 3.1.2 integration and are exploring different ways of type ahead searches. The required functionality is to achieve similar suggestions like google search from the catalog data. The Endeca Experience Manager out of box has cartridges which query dimension search for this feature, apart from these do we have any other endeca specific APIs to achieve the same functionality.

    Hi,
    The following links might help you.
    how to implement type-ahead for search
    Implementation of type-ahead functionality in Endeca JSP Ref application
    Re: Problem with endeca typeahead
    (You can even continue the hunt for the answer for this qn that forum as more Endeca experienced persons will be answering there)
    Thanks,
    Gopinath Ramasamy

Maybe you are looking for

  • How do I delete duplicate photos from my iPhone 6?

    I have double the amount of pictures on my iPhone 6, which I actually should have. (Over 11,000). I did have "save original photo" with HDR off but have since turned it off. When I synced via iTunes with iPhoto Libray a couple weeks ago, somehow the

  • Force creation of new segment

    Hello all, I have a problem with a map. In the ORIGIN schema, I have fields : ShipmentStatus LOCCode DeliveryCode In the DESTINATION Schema : LOC (with it's several child fields) I'm creating 1 LOC based in the values of ShipmentStatus and LOCCode an

  • How can i save and load .txt files

    right now i am writing an encryption prog but can't figure out how to save the encrypted text or load encrypted text for decrypting. can someone help me?

  • Crystal Reports Statement Ignored

    Can someone explain to me why there are records on my Crystal Reports that have values that are equal to "Cash" (in data column "") although my logic (Line #4) is suppose to exclude all records with "Cash" for the "" data column ?  Thanks  ! ! ! 1) 

  • My itunes freezes when I sync my Itouch

    HELP! My itunes account freezes at step 3/3 determining tracks to sync, whenever I plug in my itouch 2nd generation.  I've tried uninstalling and reinstalling itunes and I don't know what to do! I can't call tec support because my warranty is expired