我尝试着从中解脱出来。
当您尝试在Jlist中添加时间字符串,然后想要更新您的Jscroll窗格。
我将通过简单的
只需创建喜欢你的设计观点:
Jpanel1(card layout)
|
----> Jscrollpane1
|
------>Jpanel2
|
--------> Your Jlist will be here on dynamic runtime
,你可以管理面板代替的jList。
但在这里我用列表
public void getUpdateOldWorkTimeList()
{
List<String> workTimeList;
SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
workTimeList=getMyTimeList(); // here you put your work time array
Thread.sleep(100);
return null;
}
};
mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("state")) {
if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
jPanel2.removeAll();
jPanel2.revalidate();
jPanel2.repaint();
for (int i = 0; i < workTimeList.size(); i++) {
jPanel2.add(new ModelJList()).setVisible(true);
}
}
}
});
jPanel3.setLayout(new model.WrapLayout(FlowLayout.CENTER, 1, 0));
jPanel1.setBackground(new Color(0, 0, 0, 0));
jScrollPane1.setBackground(new Color(0, 0, 0, 0));
i
jScrollPane1.getVerticalScrollBar().setUnitIncrement(16);
int remainScroll=jScrollPane1.getVerticalScrollBar().getMaximum()- jScrollPane1.getVerticalScrollBar().getModel().getExtent();
jScrollPane1.getVerticalScrollBar().setValue(remainScroll);
jPanel1.removeAll();
jPanel1.add(jScrollPane1);
jPanel1.revalidate();
jPanel1.repaint();
}去
两件事必须提醒:
列表模型类:你需要实现。(当你看起来你觉得你想要的)。
getMyTimeList()方法来数组列表转换。
我已经实现了它为聊天应用程序添加发送方和接收方的聊天。
所有最优秀的
阅读JList的API,在那里你会发现链接'如何使用Lists'包含一个工作示例。 – camickr
*“我已经尝试了一切,目前为止没有任何工作”*鉴于(至少)一件事情应该起作用,您没有尝试过“一切”似乎是合乎逻辑的。顺便说一句 - 更新列表时,不要触摸列表***或***滚动窗格,只需更改“ListModel”。其他一切都会自动更新。 –
谢谢@AndrewThompson,我想出了如何使用DefaultListModel及其工作! –