Hi all

We have to create a program that will require a lot of database interaction.

I would like to create a JList with all events where a user can select an event he would like to edit.
Is there a good way to store ID's into the list and retrieve them easily? Without having to put the ID into the displayed text and then fooling around with substring etc...

Thanks in advance
Greetings, Kenny

Recommended Answers

All 5 Replies

You could create a little class to hold the event description and the database ID (and maybe any other relevant stuff). You can add those class members to the JList, and it will display them by calling their toString() method, so define a toString() that just returns the event description. When you query the selected item, you'll get the whole object (not just the displyed string), so you can retrieve its ID directly from it

Great, didn't know that was possible :)
Thanks, that's really a great help :)

Greets, Kenny.

Hi

I have one more question.
I know I could test this, but we're still designing, and there's little time, so if anyone who already knows could just tell me that would come in quite handy.

Is it possible to do this (what I asked before) with a dropdown list too? I bet the answer is yes, but I wanted to make sure.

Tanks in advance
Greets, Kenny

Yes

Ok, thanks :icon_wink:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.