Foros del Web » Programación para mayores de 30 ;) » Java »

[SOLUCIONADO] Mostrar arraylist de objetos a jlist..

Estas en el tema de Mostrar arraylist de objetos a jlist.. en el foro de Java en Foros del Web. Hola, buenas a todos. Mi problema es que quiero mostrar un arraylist de objetos(en este caso jugadores) en un jlist. La cosa es que no ...
  #1 (permalink)  
Antiguo 13/11/2015, 04:48
 
Fecha de Ingreso: junio-2015
Mensajes: 11
Antigüedad: 8 años, 10 meses
Puntos: 0
Pregunta Mostrar arraylist de objetos a jlist..

Hola, buenas a todos. Mi problema es que quiero mostrar un arraylist de objetos(en este caso jugadores) en un jlist. La cosa es que no se como asignarlo, ya que yo le doy a registrar jugador y no me sale el jugador en el jlist que tengo hecho. Me sale como el tipico fallo de java3453485@registro o algo asi, el tipico de mostrar el objeto dentro del arraylist.

Bueno la cosa es, si sabeis alguna forma de mostrar los jugadores que creo al darle a registrar al jlist. Mi codigo es el siguiente:

He quitado algunas cosas del programa ya que se pasa de los 1000 caracteres el comentario..

Programa:

Código Java:
Ver original
  1. public class RegistroClientes2 extends JFrame implements ChangeListener, ActionListener {
  2. //Nuevo panel jugadores ya inscritos
  3.    
  4.     private static ArrayList<jugador> jugadores = new ArrayList<jugador>();
  5.    
  6.    
  7.    
  8.    
  9.    
  10.     private JList listDatos = new JList(jugadores.toArray());
  11.     private JLabel lblTodosLosJugadores = new JLabel("Jugadores inscritos en la FEB:");
  12.     private JSeparator separator = new JSeparator();
  13.     private JSeparator separator_1 = new JSeparator();
  14.     private final JPanel panel_2 = new JPanel();
  15.  
  16.  
  17.    
  18.     /**
  19.      * Launch the application.
  20.      */
  21.     public static void main(String[] args) {
  22.        
  23.         EventQueue.invokeLater(new Runnable() {
  24.             public void run() {
  25.                 try {
  26.                     RegistroClientes2 frame = new RegistroClientes2();
  27.                     frame.setVisible(true);
  28.                 } catch (Exception e) {
  29.                     e.printStackTrace();
  30.                 }
  31.             }
  32.         });
  33.        
  34.         System.out.println(jugadores.isEmpty());
  35.        
  36.         jugador j1 = new jugador("Michael", "Jordan", "Hombre", 54,"RRTTTEEE", "Chi town","USA",
  37.                 "", "Chicago", "566899", "555 654 8999", "thegreatestmail", "196","90", "FC Barcelona Lassa",
  38.                 "Senior", "Liga Endesa", 23, "escolta");
  39.        
  40.         jugadores.add(j1);
  41.         System.out.println(jugadores.isEmpty());
  42.        
  43.         for(int i = 0; i < jugadores.size(); i ++){
  44.             System.out.println(jugadores.get(i).verInfoJug());
  45.            
  46.         }
  47.        
  48.     }
  49.  
  50.     /**
  51.      * Create the frame.
  52.      */
  53.     public RegistroClientes2() {
  54.        
  55.        
  56.         //Boton Registrar
  57.         btnRegistro.setBounds(240, 446, 139, 23);
  58.         panel.add(btnRegistro);
  59.         btnRegistro.setEnabled(false);
  60.         btnRegistro.addActionListener(this);
  61.        
  62.         //Mostrar Jugadores Creados
  63.         tabbedPane.addTab("Jugadores existentes", null, panel_1, null);
  64.         panel_1.setLayout(null);
  65.         listDatos.setBounds(26, 65, 560, 408);
  66.         Border border = LineBorder.createBlackLineBorder();
  67.         listDatos.setBorder(border);
  68.         panel_1.add(listDatos);
  69.  
  70.         lblTodosLosJugadores.setFont(new Font("Arial", Font.BOLD, 18));
  71.         lblTodosLosJugadores.setBounds(26, 32, 560, 22);
  72.        
  73.         panel_1.add(lblTodosLosJugadores);
  74.        
  75.         tabbedPane.addTab("Equipos", null, panel_2, null);
  76.     }
  77.  
  78.     @Override
  79.     public void stateChanged(ChangeEvent e) {
  80.         if(e.getSource().equals(checkClickAquSi)){
  81.             if(checkClickAquSi.isSelected()){
  82.                 textCM.setEnabled(true);
  83.                 textKG.setEnabled(true);
  84.                 cbEquipos.setEnabled(true);
  85.                 chckbxBase.setEnabled(true);
  86.                 chckbxEscolta.setEnabled(true);
  87.                 chckbxAlero.setEnabled(true);
  88.                 chckbxAlapvot.setEnabled(true);
  89.                 chckbxPvot.setEnabled(true);
  90.                 chckbxRegistro.setEnabled(true);
  91.                 spinnerNumero.setEnabled(true);
  92.                 comboBoxCat.setEnabled(true);
  93.                 comboBoxCompeti.setEnabled(true);
  94.             }
  95.         }
  96.        
  97.         if(e.getSource().equals(checkClickAquSi)){
  98.             if(checkClickAquSi.isSelected() == false){
  99.                 textCM.setEnabled(false);
  100.                 textKG.setEnabled(false);
  101.                 cbEquipos.setEnabled(false);
  102.                 chckbxBase.setEnabled(false);
  103.                 chckbxEscolta.setEnabled(false);
  104.                 chckbxAlero.setEnabled(false);
  105.                 chckbxAlapvot.setEnabled(false);
  106.                 chckbxPvot.setEnabled(false);
  107.                 chckbxRegistro.setEnabled(false);
  108.                 spinnerNumero.setEnabled(false);
  109.                 comboBoxCat.setEnabled(false);
  110.                 comboBoxCompeti.setEnabled(false);
  111.             }
  112.         }
  113.         if(e.getSource().equals(chckbxRegistro)){
  114.             if(chckbxRegistro.isSelected() == true){
  115.                 btnRegistro.setEnabled(true);
  116.             }
  117.         }
  118.         if(e.getSource().equals(chckbxRegistro)){
  119.             if(chckbxRegistro.isSelected() == false){
  120.                 btnRegistro.setEnabled(false);
  121.             }
  122.         }
  123.        
  124.     }
  125.  
  126.     @Override
  127.     public void actionPerformed(ActionEvent e) {
  128.         if(e.getSource().equals(comboBoxPaises)){
  129.             if(comboBoxPaises.getSelectedItem().toString().equalsIgnoreCase("España")){
  130.                 comboBoxProvincias.setEnabled(true);
  131.             }
  132.         }
  133.         if(e.getSource().equals(comboBoxPaises)){
  134.             if(!comboBoxPaises.getSelectedItem().toString().equalsIgnoreCase("España")){
  135.                 comboBoxProvincias.setEnabled(false);
  136.             }
  137.         }
  138.         if(e.getSource().equals(mnSalir)){
  139.             Object[] txtSalir = {"SI", "NO"};
  140.            
  141.             int opcion = JOptionPane.showOptionDialog(getContentPane(),
  142.                     "¿Seguro que deseas salir?",
  143.                     "Estas a un click de salir",
  144.                     JOptionPane.YES_NO_OPTION,
  145.                     JOptionPane.QUESTION_MESSAGE,
  146.                     null,
  147.                     txtSalir,
  148.                     txtSalir[1]);
  149.            
  150.             if (opcion == 0){
  151.                 System.exit(0);
  152.             }
  153.         }
  154.        
  155.         if(e.getSource().equals(btnRegistro)){
  156.            
  157.             int edadSpin = Integer.parseInt(edad.getValue().toString());
  158.             int numeroSpin = Integer.parseInt(spinnerNumero.getValue().toString());
  159.            
  160.             if(chckbxBase.isSelected()){ base = chckbxBase.getText(); }
  161.             if(chckbxEscolta.isSelected()){ escolta = chckbxEscolta.getText(); }
  162.             if(chckbxAlero.isSelected()){ alero = chckbxAlero.getText(); }
  163.             if(chckbxAlapvot.isSelected()){ alapivot = chckbxAlapvot.getText(); }
  164.             if(chckbxPvot.isSelected()){ pivot = chckbxPvot.getText(); }
  165.            
  166.             jugador j = new jugador(textNombre.getText(), textApellido.getText(),
  167.                     grupoSexo.getSelection().getActionCommand(), edadSpin,
  168.                     textDNI.getText(), textCalle.getText(), comboBoxPaises.getSelectedItem().toString(),
  169.                     comboBoxProvincias.getSelectedItem().toString(), textCiudad.getText(),
  170.                     textCod.getText(), textTLF.getText(), textEmail.getText(), textCM.getText(),
  171.                     textKG.getText(), cbEquipos.getSelectedItem().toString(),
  172.                     comboBoxCat.getSelectedItem().toString(), comboBoxCompeti.getSelectedItem().toString(),
  173.                     numeroSpin, base+" "+ escolta + " " + alero + " " + alapivot + " " + pivot);
  174.             jugadores.add(j);
  175.         }
  176.        
  177.        
  178.     }
  179. }

La cosa es que si creo un jugador desde el main si que me sale, pero si le doy a registrar no me guarda en el arralist y a parte que no me muestra el jugador ya creado en el jlist.

Si me pudierais ayudar seria de agradecimiento ya que he probado con todo y nada..

Etiquetas: arraylist, jframe, objetos, programa
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:49.