I made the example of the book "Java How to program".
I'm having trouble with the copyJList.setListData (colorJList.getSelectedValue ()) line;
Someone could 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 giving this error:
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 can not be converted to java.lang.Object []) method javax.swing.JList.setListData (java.util.Vector) is not applicable (argument mismatch; java.lang.Object can not be converted to java.util.Vector)
Select the list items to assign to another list, every time you click the button it generates the error