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 Select one id from JList.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Select one id from JList...." Watch "Select one id from JList...." New topic

Select one id from JList....

paul beppe
Ranch Hand

Joined: Aug 09, 2012
Posts: 86
Hi!!! everybody....

I'm paul and my eanglish is bad i hope you can unserstand my problem.

i'm creating one program with this db i have one table and i have id(auto_increment), nome, mp3, testo

in this program add name of mp3 in JList selecting the table with JComoBox...this is code:

here it's ok!!!

now i want select name of mp3 in JList and i want add file .txt in JTextArea and to play song selected...this is code:

and i have class QueryResult...this is cod:

from many days i don't resolve this problem!!!


Ihope you can understand my problem...
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

Hi Paul,
Welcome to the Ranch!

Why did you create 5 topics for the same issue? Please create only one message for your issue. Using all caps is considered shouting, so, please avoid that. As you are new here, I would also like to point you out to a link How To Ask Questions which explains how to ask questions effectively and nicely.

For your issue:
You are adding a list of String values to the JList. These strings are of the format "".
When you call list.getSelectedValue(), you will get back this String value. So, if you want to get the 'name' part from this string, you should use the String methods like indexOf() and substring() to get the value and then use it.

I would also like to point out the various issues in your code:
1) You should add a ListSelecttionListener to listen to selection changes and not MouseListener. You can read about this here

2) You are using Statement and appending the value to the where condition. This is not a good coding practice. You should use PreparedStatement.

3) You have the GUI code and the DB code in the same place. You should look to separate these into separate classes.

I agree. Here's the link:
subject: Select one id from JList....
It's not a secret anymore!