java refreshing an array into jList

前端 未结 2 998
你的背包
你的背包 2021-01-13 04:48

OK so I have a JList and the content is provided with an array. I know how to add elements to an array but I want to know how to refresh a JList... or is it even possible? I

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 05:24

    One good approach is to create a ListModel to manage the data for you and handle updates.

    Something like:

    DefaultListModel listModel=new DefaultListModel();
    for (int i=0; i

    Then you can simply make changes via the list model e.g.

    listModel.addElement("New item");
    listModel.removeElementAt(1); // remove the element at position 1
    

提交回复
热议问题