Two Laptop Bag*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Select one id from JList...." Watch "Select one id from JList...." New topic
Author

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 db...in 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!!!

HELP ME PLEASE!!!

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

Joined: Oct 16, 2003
Posts: 1076
    
  10

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 "1.name".
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.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Select one id from JList....
 
Similar Threads
Mapping a method data of a custom class to an Enum
JList Problem
Someone pls explain these technologies...
JList data from a database - 2 columns - 1 column hidden
Problem with JScrollPane