aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to get the selected item in JList to and use casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get the selected item in JList to and use casting" Watch "How to get the selected item in JList to and use casting" New topic
Author

How to get the selected item in JList to and use casting

Dan Quartz
Greenhorn

Joined: Mar 29, 2013
Posts: 3
In a part of my program, I have a JList that it has a list on locations, and I got an API that it should use an item from the JList and print out the weather of that location. So now I can not do it, because I use




but there is an error: Type mismatch: cannot convert from int to WeatherAPI.

This is the example of the API that works:


So I dont want to get the first option, i want to get the selected location by the user. It's all about casting. I also tried this which did not work:



I got the rest of the code, that it uses the "firstMatch, but it only uses it when its type is WeatherAPI. Also I got a bit of help from someone who has already done this program. Here is what he mentioned: Do you have a list of stations somewhere which you use to put information into your locList? If you do, when a user clicks something in the JList, you can use locList.getSelectedIndex() as the parameter for a stations.get call and the answer you get can be placed inside chosen.


So Do you have any idea?


Thank in advance.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
What is the point of this question?

You posted this question and got an answer 2 hours earlier:

http://stackoverflow.com/questions/15723134/how-to-get-the-selected-item-in-jlist-to-and-use-casting

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the selected item in JList to and use casting