我正在阅读JList“desList”中的一些图像,如下所示:
public class DualListBox extends JPanel {
ArrayList<String> nombreArrayList = new ArrayList<String>();
private class compareListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
metodo m = new metodo();
if (destList.getSelectedIndex()==-1){
JOptionPane.showMessageDialog(null, "YOU MUST SELECT AN IMAGE", "ERROR", JOptionPane.ERROR_MESSAGE);
}else{
model = destList.getModel();
for(int i=0; i < model.getSize(); i++){
lista = (String) model.getElementAt(i);
nombreArrayList.add(i, lista);
System.out.println(nombreArrayList.get(i)); //HERE A GOT ALL IMAGES AND PRINT OUT WITHOUT PROBLEM
}
m.test(); //HERE I CALL ANOTHER CLASS WITHOUT PROBLEM
}
}
}
}
public class LeftSide extends JPanel { //THIS IS MY ANOTHER CLASS
public LeftSide() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
Border compound1 = null, compound2;
Border redline = BorderFactory.createLineBorder(Color.red);
c.gridx = 1;
c.gridy = 0;
final ImageIcon icon = new ImageIcon ("Historial_salidas/Bordes/Original Image.jpg"); //HERE IAM USING AN ABSOLUTELY PATH BUT IN REAL A NEED TO PUT THE FIRST IMAGE READED FROM "nombreArrayList"
final Icon icono = new ImageIcon(icon.getImage().getScaledInstance(130, 130, Image.SCALE_DEFAULT));
compound2 = BorderFactory.createCompoundBorder(redline, compound1);
one.setBorder(compound2);
one.setIcon(icono);
one.repaint();
left.add(one);
add(left, c);
问题是当我尝试将来自“nombreArrayList”的图像放到我的另一个类中的3个不同的JLabel时,在这个例子中,“one”是我的第一个JLbael。任何帮助?