How can I fill several JTexField with the contents of an ArrayList?

0

The specific doubt is that you create JRadioButton in a dynamic way, that is, depending on the amount that exists in an ArrayList. From the FileManager class the user information is brought and it is required to show in its respective JTextField. This is a code segment:

    public void crearRadioButton(){
    ManejadorArchivo manejador = ManejadorArchivo.getInstance();
    ArrayList<Usuario> usuarios = manejador.getListaUsuarios();
    JPanel panelUsuarios = new JPanel();
    panelUsuarios.setLayout(new FlowLayout());


    Component botones;

    for(Usuario usr: usuarios){
        botones = panelUsuarios.add(new JRadioButton((usr.toString())));
        grupo.add((AbstractButton) botones);

    } 

    panel.add(panelUsuarios, BorderLayout.CENTER);
    panelUsuarios.setBounds(228, 11, 265, 378);

    panel.setVisible(true);
}

What I need is that when choosing the name of a user through the JRadioButton I show all the information of a certain user selected in the JTexfield assigned (Name, Maternal surname, Last name).

    
asked by Johan Cancino 20.05.2017 в 21:19
source

1 answer

1

If you add an ActionListener to each JRadioButton at the time of creating them, then when coding the actionPerformed (ActionEvent event) method, you can invoke the event.getSource () method and cast JRadioButton. Obtained in this way the JRadioButton in question, you can go through the list again until you find the user whose toString () matches the name of the obtained JRadioButton and once the user has obtained the data in the JTextFields.

    
answered by 24.05.2017 в 06:57