File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Jlist and Jtextfield Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jlist and Jtextfield" Watch "Jlist and Jtextfield" New topic

Jlist and Jtextfield

Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
I have the following problem but first the situation :
I have succesfully connected to an existing Ms-Access database and retrieved the resultset of three colomns.
One colomn of the resultset is "name" which I'd like to place in a Jlist.
To the right of my Jlist are some Jtextfields which are the other fields of my database and are also in my resultset (the other columns).
Here's what I want, when I click on a name in the Jlist I want the Jtextfields to change also with their corresponding values...
Here's the code of what I already have.
Somebody already gave me some help and told me to use Vectors.
But it's not really working.

// create a statement handler
Statement sqlStatement = databaseConnection.createStatement();

// create a sql-string
ResultSet results = sqlStatement.executeQuery(sql);
ResultSetMetaData rsmd = results.getMetaData();
int totCol = rsmd.getColumnCount();

// here are the two vectors one for the columns
one for the rows but how do I USE THEM ???
while (
Vector newCol = new Vector();
for (int i =1 ; i <= totCol; i++ )

// close connection
System.out.println("the connection is closed !");

} catch (SQLException sqle) {
Can anybody help me ??
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
You could create some class to hold each row of the resulset. Put in a toString() which returns the Name. Put all of those in a Vector and create your JList. When something is selected, cast the Object selected to your class and use the setText() of the JTextfields to fill with the other values in your class.
suheel hussain

Joined: Nov 01, 2001
Posts: 16
I had a simialr problem where selecting an entry in JList brings
up an internal frame, etc. My solution was to create a hash table
and use JList entry as a key for corresponding string to be
displayed in text field. Thus, selected JList entry is used to
search corresponding text field in hash table.
(I prefer using Hashtable instead of Vector.)
I agree. Here's the link:
subject: Jlist and Jtextfield
It's not a secret anymore!