Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying ArrayList in JScrollPane & Panel 1

Status
Not open for further replies.

asiavoices

Programmer
Sep 20, 2001
90
CA
Hello all,

I have another question that I'd like to try and code, learn and to see if this was possible....

How can I display my recordset, created from an ArrayList into a JPanel I've created? I'd like to have the people be ale to scroll through the list if possible.

For eample, I'm thinking of putting the recordset into the JScrollPane and then putting it into the Panel.

=========================
= My list =
=========================
= =
= item1 cost taxID =
= item2 cost taxID =
= ............ =
= =
= =
=========================

The list is inside a JScrollPane.

How do I go about doing that? I know you can put a Vector into a JScrollPane but "not " an ArrayList.

Any ideas?

Thanks,

Christopher


 
You much better off going with a Jtable or a JList as suggested by pipk, inside a JScrollPane. As a correction, there is no way to "put a Vector into a JScrollPane". That statement infers that there is some method in JScrollPane that accepts a Vector for display, this is not the case. Regardless, it would be very easy to create a Vector out of an ArrayList if that is what was required.
 
Hello wushutwist ,

Thank you. How does one "create" a Vector from an ArrayList?

Thanks,

C
 
The Vector class has a constructor that accepts a Collection objects to place in the Vector. Since ArrayList is of type Collection, it then becomes trivial. Example:
Code:
ArrayList al = new ArrayList();
al.add(new Integer(1));
Vector vec = new Vector(al);
System.out.println(vec);
Here are the Javadocs for the Overloaded Vector Constructor:
Code:
Vector

public Vector(Collection c)

Constructs a vector containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Parameters:

c - the collection whose elements are to be placed into this vector.

Since: 

1.2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top