Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Jlist Problem

Options
  • 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 Posts: 839 ✭✭✭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