Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6577021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:35:00+00:00 2026-05-25T15:35:00+00:00

I am following a series of Java tutorials in an attempt to learn it.

  • 0

I am following a series of Java tutorials in an attempt to learn it. I have a question about tutorial 72.

Link: http://www.youtube.com/watch?v=9z_8yEv7nIc&feature=relmfu

At 7:02 of the video, this statement is written. However, this method has been deprecated in Java 1.7.

RightList.setListData(LeftList.getSelectedValues());

Eclipse returns the following error:

    Object[] javax.swing.JList.getSelectedValues()
    getSelectedValues
    @Deprecated
    public Object[] getSelectedValues()
    Deprecated. As of JDK 1.7, replaced by getSelectedValuesList()
    Returns an array of all the selected values, in increasing order based on their indices in the list.
    Returns:
    the selected values, or an empty array if nothing is selected
    See Also:
    isSelectedIndex(int), getModel(), addListSelectionListener(javax.swing.event.ListSelectionListener)

But this returns an error saying ‘The method setListData(Object[]) in the type JList is not applicable for the arguments (List)'.

What is the correct way to replace the above statement?


Also, I want to take this opportunity to ask a another unrelated question. Is it better to initialize variables outside the method like so:

    private         JList       LeftList    =   new JList();
    private         JList       RightList   =   new JList();
    private         JButton     Move        =   new JButton("Move -->");

    private static  String[]    Items       =   {"Item 1", "Item 2","Item 3","Item 4","Item 5"};

Compared to (As shown in the video): Declaring variables outside the class like above, but assigning values to them inside the method?

Does either perform better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:35:01+00:00Added an answer on May 25, 2026 at 3:35 pm

    According to JList javadoc for Java7 I see that indeed you have no option – the two APIs (getSelectedValuesList and setDataList) are unrelated.

    To solve it, a simple solution would be to perform LeftList.getSelectedValuesList().toArray() – it will provide you with an array suitable for setDataList. Disclaimer: I don’t know if this is the “correct” usage recommended by Java, but it should work.

    Also, note that a deprecated API does not mean it doesn’t work – if you feel you don’t want to invest time in it now, you can still use the old API (like in your situation where you are doing a tutorial and not some ongoing product that will be in production for the next 10 years)

    As for the 2nd question – it is a matter of taste, I prefer declaring the variables without initializing them in the class declaration and setting them with values in the constructor. It is customary to give initial values to constants (e.g. public static final String AAA = "XYZ"; )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A quick question. I have a series of DIVs with the following classes .level1
I have the following d attribute for SVG but the question is about regular
I've been following these 2 tutorials to setup a list & click events: http://mfarhan133.wordpress.com/2010/10/14/list-view-tutorial-for-android/
I have imported a time series with dates of the following format: test =
Following Izb's question about Best binary XML format for JavaME , I'm looking for
My question is about memory use and objects in actionscript 2. If I have
Is there a way to tidy-up the following code, rather than a series of
Following on from my recent question on Large, Complex Objects as a Web Service
Following my question regarding a .NET YAML Library ... as there doesn't seem to
Following this question: Good crash reporting library in c# Is there any library like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.