简体   繁体   中英

Arraylist into JList problems

I have trouble putting my arrayList into a Jlist . This is what I have:

Main Class:

  package domain;

 import java.util.ArrayList;

public static void main(String[] args) {
    ArrayList<String> purposeCategories = new ArrayList<String>();
    purposeCategories.add("Behavioral");
    purposeCategories.add("Structural");
    purposeCategories.add("Creational");
 }

I have put my list declaration in my Jframe class and I have the import domain.main; But it says that it doesn't recognize purposeCategories ...What am I forgetting?

 JList list_purpose = new JList(purposeCategories.toArray());
    list_purpose.setBounds(50, 121, 121, 63);
    contentPane.add(list_purpose);

Also sorry for my English and thank you for your time:D

The list is in a different scope. Do this in your Jframe class:

public MyFrame(List<String> data) {
//now put your code for the Jlist   here using the variable name "data" for your list
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM