protected void editar() {
    ProdutoDaoImp pdao = new ProdutoDaoImp();
    int linha = table.getSelectedRow();
    CategoriaDaoImp cdao = new CategoriaDaoImp();
    ArrayList<Categoria> c = (ArrayList<Categoria>) cdao.listar();
    ArrayList<Produto> p = (ArrayList<Produto>) pdao.listar();

    txtid.setText(String.valueOf(p.get(linha).getId()));
    txtnome.setText(p.get(linha).getNome());
    txtcodigobarra.setText(String.valueOf(p.get(linha).getCodigodebarras()));
    txtdescricao.setText(p.get(linha).getDescricao());
    txtcusto.setText(String.valueOf(p.get(linha).getCusto()));
    txtmargemlucro.setText(String.valueOf(p.get(linha).getMargemdelucro()));

    for (Categoria categoria : cdao.listar()) {
      if (p.get(linha).getCategoria() == categoria.getId())
        combocategoria.setSelectedItem(categoria.getCategoria());
    }
    combounidade.setSelectedItem(p.get(linha).getUnidade());
    model.fireTableDataChanged();
  }