0

I need help with this:

I have a .txt file with strings like luis;123;456;890;11/11/1111, from this I needed to fulfill a combobox with just the position 0 (luis, on this example), and I've done it! But as I select the option from combobox I also need to fill a text field with position 2 of the string referring to the line selected on the combobox. What should I do?

Code for filling combobox:

DefaultComboBoxModel<String> ComboClientes;
    public JFrameRegVendas() {
        initComponents();        
    }    
public void popularCombo() throws FileNotFoundException, IOException{
            ComboClientes = new DefaultComboBoxModel<>();
               String clientes = "";
               FileReader fr;
               fr = new FileReader("clientes.txt");
               BufferedReader br = new BufferedReader(fr);
               while ((clientes = br.readLine())!=null){                        
                    String quebra [] = clientes.split(";");
                    String nome = quebra[0];
                    String cpf = quebra[2];
                    ComboClientes.addElement(nome);
                    
                }
               br.close();
               fr.close();
               jComboBoxCliente.setModel(ComboClientes);
            }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Create a **Client** class to support each data line – DevilsHnd - 退職した Aug 22 '21 at 09:31
  • Add a custom Object to the combo box to hold all the data. See: https://stackoverflow.com/questions/5010537/java-swing-jcombobox-is-it-possible-to-have-hidden-data-for-each-item-in-the-l/5010548#5010548 for a working example. – camickr Aug 22 '21 at 14:14

0 Answers0