1
I did the example of the book "Java How to program".
I’m having trouble on the line copyJList.setListData(colorJList.getSelectedValue());
Could someone help.
package LvProg8.exercicio.capitulo14.exemp8;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MultipleSelectionFrame extends JFrame {
private JList colorJList; //lista para exibir cores
private JList copyJList;
private JButton copyJButton;
private static final String[] colorNames = {
"Black", "Blue", "Cyan", "Dark Gray", "Gray", "Green", "Light Gray", "Magenta"
, "Orange", "Pink", "Red", "White", "Yellow"
};
//Contrutor
public MultipleSelectionFrame()
{
super("Multiplas seleções");
setLayout(new FlowLayout());
colorJList = new JList(colorNames);
colorJList.setVisibleRowCount(5); //
colorJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
System.out.println(colorJList.getSelectedValue());
//adiciona JScrollPane que contem JList ao frame
add(new JScrollPane(colorJList));
copyJButton = new JButton("Copy >>>");
copyJButton.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copyJList.setListData(colorJList.getSelectedValue());
}
}
);
add(copyJButton);
copyJList = new JList();
copyJList.setVisibleRowCount(5);
copyJList.setFixedCellWidth(100);
copyJList.setFixedCellHeight(15);
copyJList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
add(new JScrollPane(copyJList));
}
}
You’re making this mistake:
Error:(35, 34) java: no suitable method found for setListData(java.lang.Object) method javax.swing.Jlist.setListData(java.lang.Object[]) is not applicable (argument Mismatch; java.lang.Object cannot be converted to java.lang.Object[]) method javax.swing.Jlist.setListData(java.util.Vector) is not applicable (argument Mismatch; java.lang.Object cannot be converted to java.util.Vector)
Selecting items from the list to assign to another list, every time you click on the button generates the error
What is the mistake that is happening?
– rodrigo.oliveira