Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Jlist Problem

  • 17-02-2004 10:40AM
    #1
    Closed Accounts Posts: 537 ✭✭✭


    I was wondering if you can update a jlist the same way you update a combo box after getting information from an sql statement


    Here is my code but the compiler doesnt recognize the add feature





    private void populateQueue()
    {
    try
    {
    String sql = "SELECT DISTINCT QueueRelationTable.Queue FROM QueueRelationTable;";
    ResultSet result = stmt.executeQuery(sql);

    while(result.next())
    {
    jList1.add(result.getString("Queue")); // here is where the problem is
    }
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }

    }


    Thanking you in advance Johnny Bravo


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    The add method takes a Component as an argument. Take a look at JLists on www.javaalamanac.com


  • Registered Users, Registered Users 2 Posts: 821 ✭✭✭Dr Pepper


    JB,

    As far as I know, a JList doesn't really store a list of items.. It just displays it. You can store the items in a vector.
    Vector V = new Vector();
    
    V.add("Item 1");
    V.add("Item 2");
    
    //Instantiate the JList
    JList jList1 = new JList( V );
    

    If you want to add items after the JList is created/displayed, you have to add them to the Vector, V and then reset the JList to display the contents of the Vector:
    //...
    V.add(result.getString("Queue")); 
    //...
    jList1.setListData(V);
    

    You can use an array instead of a vector but it's handier to use a vector because you can add/take away from it more easily!.. Arrays have a fixed size..


Advertisement