问题描述:

http://i.stack.imgur.com/8rQW1.png

JScrollPane scrollPane_4 = new JScrollPane();

scrollPane_4.setViewportView(list_4);

final JList list_4 = new JList(modelItems);

list_4.setBounds(428, 39, 294, 187);

JButton btnNewButton_4 = new JButton("Refresh");

btnNewButton_4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

modelItems.clear();

arrayOfItems.clear();

for(RSItem d : Inventory.getAll())

{

arrayOfItems.add(d);

modelItems.addElement("Item: "+d.getID()+" at spot: "+(d.getIndex()+1));

}

}

});

I am not sure what is causing this to happen. I have many other JLists with almost the exact same code and this does not occur.

网友答案:

I'm pretty sure that this is not your code. The following two lines

  scrollPane_4.setViewportView(list_4);
  final JList list_4 = new JList(modelItems);

are in reverse order. You first set the viewport view before you even declare your list. Make sure that you do not set the view to null in this line and reverse order of those two.

相关阅读:
Top