You need to check if the JList does contain so much values.
You're not coding safe. You need to take more care.
You can never expect a value to be there as you need it - always check if the value is valid before you use it!
"TorstenH" want to say you that you have to check the "index" value before using it to set the selected item. You should check "index" value whether it is in the range of your image list size.
The problem would be that you tried to update the GUI while you where using it. SwingUtilities.InvokeLater()[^] would cause the Thread to wait and update the GUI when possible.
Thanks for your suggestions..
My problem is I want to change the item in a Jlist Programmatically.
That's why I wanted to use this but Robot(AWT key Press Event)not working.
My code is:
listener = new ListSelectionListener() {
@Override
publicvoid valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));
}
}
}
imageList.addListSelectionListener(listener);
Well the code is working fine but I want to change the next image using a button or something else
How can I do this?
Please help me in this?