posted 20 years ago
Hi,
I have a JList that displays images.
I want drag drop functinality to be added to it, such that i can drag an image from one location in the list and drop it to another location, in the same list only.Please let me know the rite approach to do the same.
List with images -
public class JListWithImages extends JList {
/** Constructs a List with only images.
*
*/
public JListWithImages() {
setCellRenderer(new CustomCellRenderer());
}
class CustomCellRenderer implements ListCellRenderer {
public Component getListCellRendererComponent (
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
Component component = (Component)value;
component.setBackground(isSelected ? Color.black : Color.white);
component.setForeground(isSelected ? Color.white : Color.black);
return component;
}
}
}
how i m defining my list
JListWithImages imageList;
how i m adding images to list -
imageList.setListData(imagesVector);
where imagesVector has panels added on it like this -
//getIconImage() of PageImage returns an Image.
JPanel jImagesPane1 = new JPanel();
jImagesPane1.add(
new JLabel(
new ImageIcon(
((PageImage) m_tempPageImageList.get(i))
.getIconImage()
)
)
);
imagesVector.add(jImagesPane1);
Thanxs,
Shelly