morrow
morrow

Reputation: 316

Java - JList.getSelectedValuesList() not working in jar file

I was writing a program with swing and used a JList for displaying several Objects E. I wanted to be able remove Objects from the list with a button. Within the ActionListener i coded:

List<Data> datas = dataList.getSelectedValuesList();
for(Data data : datas)
    deleteData(data);
dataList.setListData(getDatas());

This worked perfectly when running it in Eclipse or in the console with 'java -jar xyz.jar'. However, when double clicking on the .jar-file, the remove button wouldn't work at all, nothing was removed from the list and not even an error was produced.

Therefore, I tested the List.getSelectedValues() method:

Object[] datas = dataList.getSelectedValues();
for(Object data : datas)
     deleteData((Data)data);
dataList.setListData(getDatas());

This method worked perfectly. However, this method is deprecated since JDK 1.7 in favor of getSelectedValuesList(). Can someone explain me the problem? Is it a Java build issue? How can I still use the non-deprecated method?

Thanks!

Upvotes: 2

Views: 2033

Answers (1)

Danny
Danny

Reputation: 7518

You likely have multiple versions of Java installed on you computer. When you are running it from the command line it is running your application with one versions of Java and when you double click another.

Instead of double clicking you should right click and do "Open With..." and select the version of Java that your application was compiled with.

Upvotes: 3

Related Questions