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

    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) {
    //System.out.println("insert");

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


    System.out.println(s);

    ArrayList ar = new CustomerDAO().getCustomerNames(s);
    //System.out.println(ar.get(i));

    //jComboBox1.removeAll();
    int howMany = ar.size();

    final String[] placeArray;

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

    public void run() {

    System.out.println("inside invoke later");
    //jComboBox1.setSelectedItem(s);



    if (!b.isPopupVisible()) {
    b.setModel(new DefaultComboBoxModel(placeArray));
    b.setPopupVisible(true);
    //b.setSelectedItem(s);

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


    }
    });

    }

    thanks in advance.

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

    Default

    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, 04:03 AM
  2. Replies: 1
    Last Post: 03-14-2010, 10:03 PM
  3. how to use google finance api java
    By theseven in forum New To Java
    Replies: 1
    Last Post: 02-13-2010, 02:45 PM
  4. Java application using google calendar
    By nikolas8 in forum Java Applets
    Replies: 3
    Last Post: 03-20-2009, 12: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
  •