首页 > 解决方案 > 从组合框选择中填充文本字段

问题描述

我需要帮助:

我有一个 .txt 文件,其中包含诸如 luis;123;456;890;11/11/1111 之类的字符串,从这里我需要用位置 0 来完成一个组合框(luis,在这个例子中),我已经完成了!但是当我从组合框中选择该选项时,我还需要用字符串的位置 2 填充一个文本字段,该位置指的是在组合框中选择的行。我应该怎么办?

填充组合框的代码:

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);
            }

标签: javaswingfilecombobox

解决方案


推荐阅读