database results in drop-down


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: database results in drop-down

  1. #1
    Join Date
    Dec 2002
    Posts
    17

    database results in drop-down

    I think I understand how to display 1 value (i.e. "integra") in a drop down menu.

    What I'm stumped about is... how would I display multiple data on one line in a drop down list?

    for example... my database will return, last name, first name, phone# on one line of my JList.

    I would be using a JList with the following options:
    -setVisibleRowCount(1)
    -setSelectionModeListSelectionModel.SINGLE_SELECTION);

    I assume JList IS the thing to use in this case...

    P.S. Please keep in mind that from the example above, the items to be placed in one line of the JList may be from different tables

  2. #2
    Join Date
    Dec 2002
    Posts
    83
    Gun,

    Following your example, I'm assuming you are getting the last name, first name, phone# values all in a result set from your database. If your question is the "how" of joining tables and getting values from them, you'll have to address that before trying to display them.

    As far as displaying multiple attributes in each row, I think you can get what you're describing by gathering your result data, concatinate them into Strings, build a List of the Strings, then put that List into the JList.

    So using your example and assuming you loop through the values from your database and assign them to lastName, firstName, and phone:


    -------------------------------------------------------------------
    Vector displayVector = new Vector();
    String displayString = null;

    // start loop
    // assign values to lastName, firstName, phone
    displayString = (lastName + ", " + firstName + " " + phone); // build String
    displayVector.addElement(displayString); // add String to Vector
    // end loop

    JList myJList = new JList(displayVector); // load JList with Vector
    -------------------------------------------------------------------


    I haven't dealt with Swing in a while, just working off the API. Hope this helps some.

    -- Steven

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center