0

I'm baffled. With extensive testing I can confirm that if I add objects faster than y to the DefaultListModel connected to the JList, the JList dissapears.

Here's what I'm doing:

JPanel pane = new JPanel(new BorderLayout());
JList<LogMessage> messageList = new JList<LogMessage>(dataModel.getMessageList());
pane.add(messageList , BorderLayout.CENTER);

//add pane to JFrame etc.

After initializing the GUI I add 100 LogMessages to the DefaultListModel. What's strange is that everything works if I do Thread.sleep(10); between each of the 100 new LogMessages. If I don't - the JList vanishes.

I tried to export as a runnable jar and run it - the problem was gone. I still need to be able to run run my programs from eclipse though.

What could be causing this?

4

1 回答 1

3

所有 Swing 组件都只能在 theEvent Dispatch Thread或 the上访问EDT。如果不是,那么你就违反了摆动线程原则,你可能会遇到像你得到的那样的奇怪错误。

Runnable要发布要排队在 EDT 上运行的任务(即 a ),请使用SwingUtilities.invokeLater

于 2013-04-23T20:28:29.723 回答