Java - How do I get a all the selected values from a JList?

…衆ロ難τιáo~ 提交于 2019-12-21 09:02:21

问题


A struggling Java newbie here - help! I'm trying to: - Get all the selected values from a JList - Create an ArrayList from those values

It seems getSelectedValues is deprecated?


回答1:


Until JDK 1.6 (deprecated in 1.7):

  • public Object[] getSelectedValues()

New since JDK 1.7:

  • public List<E> getSelectedValuesList()

    Returns a list of all the selected items, in increasing order based on their indices in the list.




回答2:


As of JDK1.7 it was replaced with public List<E> getSelectedValuesList(). http://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html#getSelectedValuesList%28%29




回答3:


use getSelectedValuesList instead.

So, use public List<E> getSelectedValuesList().

It returns:

Returns a list of all the selected items, in increasing order based on their indices in the list.




回答4:


Please use getSelectedValuesList. Here is the link to the API documentation getSelectedValuesList.



来源:https://stackoverflow.com/questions/8886405/java-how-do-i-get-a-all-the-selected-values-from-a-jlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!