我正在尝试在Button的触发器中使用SwingWorker加载JComboBox值。但是单击该按钮不会加载我的JComboBox中的值。我通过publish()
方法发送数据,然后使用process()
接收数据。但是将元素映射到我的JComboBox
将不会设置模型。有什么原因吗?
private Map<JComboBox, DefaultComboBoxModel> puta()
{
Map<JComboBox, DefaultComboBoxModel> map = new HashMap<>();
map.put(view.getCb(), (DefaultComboBoxModel)view.getCb().getModel());
return map;
}
class ButtonListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
//Show Internal Frame
createFrame();
new ComboBoxWorker(puta()).execute();
}
}
private class ComboBoxWorker extends SwingWorker<Void, List>
{
public final Map<JComboBox, DefaultComboBoxModel> map;
public ComboBoxWorker(Map<JComboBox, DefaultComboBoxModel> map)
{
this.map = map;
}
@Override
protected Void doInBackground() throws Exception
{
List list = new ArrayList();
list.add(model.setGender());
publish(list);
return null;
}
@Override
protected void process(List chunks)
{
map.get(view.getCb()).addElement(chunks);
}
}