• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jlist and Jtextfield

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic