aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jlist and Jtextfield" Watch "Jlist and Jtextfield" New topic
Author

Jlist and Jtextfield

Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
Hello,
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.

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

// create a sql-string
String sql = "SELECT NAME,TYPE,LENGTH,DESCRIPT
FROM VELD ORDER BY NAME";
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 (results.next())
{
Vector newCol = new Vector();
for (int i =1 ; i <= totCol; i++ )
{
newCol.addElement(results.getObject(i));
rows.addElement(newCol);
}
}

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

} catch (SQLException sqle) {
System.err.println(sqle);
}
}
Can anybody help me ??
Thanks
Kristof
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
Greenhorn

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: http://aspose.com/file-tools
 
subject: Jlist and Jtextfield