2016-06-28 88 views
0

我有一个填充了-Integer,“Obra” - 对象散列图的Jlist,并且我有一个方法可以接收obras列表,我试图让所有在JList和尝试selectd奥夫拉斯传递作为参数传递给我的方法,但我不断收到一个错误类型不匹配如何从jlist检索对象列表

这里是我的代码

public class Emprestimo { 
private Usuario u; 
private Calendar dataRealizacao; 
private double total = 0; 

public Emprestimo(Usuario u){ 
    this.u = u; 
    dataRealizacao = Calendar.getInstance(); 
} 

public void realizaEmprestimo(Obra... o){ 
    try{...do stuff 


anotherclass 
emp = new Emprestimo(user); 
emp.realizaEmprestimo(JlistObra.getSelectedValuesList()); // here's where i get my error 

我试图做一个铸像这样

(emp.realizaEmprestimo((Obra)JlistObra.getSelectedValuesList()); 

(emp.realizaEmprestimo((Obra[])JlistObra.getSelectedValuesList()); 

,但它不工作

和我做:

emp.realizaEmprestimo((Obra) JlistObra.getSelectedValue()); 

其作品,但在我的jList

回答

0

我只是做一个选择元素它工作,不是最好的方式,但解决方案是一种解决方案:

int[] indices = JlistObra.getSelectedIndices(); 

     for (int i : indices){ 
      emp.realizaEmprestimo((Obra)JlistObra.getModel().getElementAt(i)); 
     }