在Swing Java中将元素添加到JList

在Swing Java中将元素添加到JList,第1张

在Swing Java中将元素添加到JList

您应该在单独的线程中更新列表,否则最终将阻塞事件分发线程。

请尝试以下 *** 作:

final DefaultListModel model = new DefaultListModel();final JList list = new JList(model);//another thread to update the modelfinal Thread updater = new Thread() {        @Override    public void run() {        for (int i = 0; i < 10; i++) { model.addElement(i); try {     Thread.sleep(1000); } catch (InterruptedException e) {     throw new RuntimeException(e); }        }    }};updater.start();


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4945601.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-13
下一篇2022-11-13

发表评论

登录后才能评论

评论列表(0条)

    保存