简体   繁体   English

Arraylist变成JList问题

[英]Arraylist into JList problems

I have trouble putting my arrayList into a Jlist . 我很难将arrayList放入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; 我已经将列表声明放入我的Jframe类中,并且具有导入domain.main;。 But it says that it doesn't recognize purposeCategories ...What am I forgetting? 但是它说它无法识别purposeCategoriespurposeCategories ...我忘记了什么?

 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 也对不起我的英语,谢谢您的时间:D

The list is in a different scope. 该列表在其他范围内。 Do this in your Jframe class: 在您的Jframe类中执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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