Results 1 to 2 of 2
  1. #1
    charithdula is offline Member
    Join Date
    Nov 2010
    Rep Power

    Angry How to create a google like drop down in java using a jcombobox

    I'm having trouble crating a google like drop down list in java using a jcombo.
    (I mean when I press 's' all the results starting with 's' will be displayed.)
    by the way I've created a jcombo to work like that but it seems a little unstable.:confused:.It works fine for some time and gets stuck after typing in the search keys and deleting a few keystrokes.
    Please help me solve this.
    here goes my code.

    final JTextComponent tcA = (JTextComponent) jComboBox1.getEditor().getEditorComponent();
    tcA.getDocument().addDocumentListener(new DocumentListener() {

    public void insertUpdate(DocumentEvent e) {

    String s = null;
    try {
    //s = (String) jComboBox1.getEditor().getItem();
    s = e.getDocument().getText(0, e.getDocument().getLength());
    } catch (BadLocationException ex) {


    ArrayList ar = new CustomerDAO().getCustomerNames(s);

    int howMany = ar.size();

    final String[] placeArray;

    if (howMany > 0) {
    placeArray = new String[howMany];
    final JComboBox b = jComboBox1;
    SwingUtilities.invokeLater(new Runnable() {

    public void run() {

    System.out.println("inside invoke later");

    if (!b.isPopupVisible()) {
    b.setModel(new DefaultComboBoxModel(placeArray));

    } else {
    b.setModel(new DefaultComboBoxModel(placeArray));



    thanks in advance.

  2. #2
    charithdula is offline Member
    Join Date
    Nov 2010
    Rep Power


    please note that customerDAO().getCustomerNames() returns an arrayList of names starting with the letters that I type in the combobox(the combo is editable)

Similar Threads

  1. Replies: 3
    Last Post: 03-20-2010, 05:03 AM
  2. Replies: 1
    Last Post: 03-14-2010, 11:03 PM
  3. how to use google finance api java
    By theseven in forum New To Java
    Replies: 1
    Last Post: 02-13-2010, 03:45 PM
  4. Java application using google calendar
    By nikolas8 in forum Java Applets
    Replies: 3
    Last Post: 03-20-2009, 01:49 AM
  5. JComboBox and drop-down list.....HELP!!!!!
    By Anna in forum AWT / Swing
    Replies: 1
    Last Post: 06-18-2008, 05:16 AM

Tags for this Thread

Posting Permissions

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