Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/09/2015, 11:45
Avatar de GumiCat
GumiCat
 
Fecha de Ingreso: mayo-2014
Ubicación: Argentina
Mensajes: 16
Antigüedad: 10 años
Puntos: 0
Pregunta Realizar accion al seleccionar un item de una JList

Hola, tengo un codigo que copie de otro lado:

Código Java:
Ver original
  1. import java.awt.BorderLayout;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JList;
  5. import javax.swing.JScrollPane;
  6.  
  7. public class ScrollList extends JFrame {
  8.  
  9.   JScrollPane scrollpane;
  10.  
  11.   public ScrollList() {
  12.     super("JScrollPane Demonstration");
  13.     setSize(300, 200);
  14.     setDefaultCloseOperation(EXIT_ON_CLOSE);
  15.  
  16.     String categories[] = { "Household", "Office", "Extended Family",
  17.         "Company (US)", "Company (World)", "Team", "Will",
  18.         "Birthday Card List", "High School", "Country", "Continent",
  19.         "Planet" };
  20.     JList list = new JList(categories);
  21.     scrollpane = new JScrollPane(list);
  22.  
  23.     getContentPane().add(scrollpane, BorderLayout.CENTER);
  24.   }
  25.  
  26.   public static void main(String args[]) {
  27.     ScrollList sl = new ScrollList();
  28.     sl.setVisible(true);
  29.   }
  30. }

que si que lo entiendo perfectamente ahora quiero saber cómo se hace para que cuando el usuario haga click en uno de los items se muestre una imagen por ejemplo o haga algo, se muestren otros componentes, etc.

Agradeceria la ayuda! :D