Insert data into the DB and then change tab

Asked

Viewed 53 times

0

How can I skip to tab after entering data into my database?

    private void botaoAvancarTab1ActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    String inserirArtigo = "";
    String nome = txtNome.getText();
    String descricao = txtDescricao.getText();
    String designacaoComercial = txtDesignacaoComercial.getText();
    String stock = txtStockAtual.getText();
    String ativo = "";
    if (jCheckBoxAtivo.isSelected()) {
        ativo = "1";
    } else {
        ativo = "0";
    }

    inserirArtigo = "insert into artigo (Nome, Descricao, Designacao_Comercial, Ativo,Stock) "
            + "values ('" + nome + "','" + descricao + "','" + designacaoComercial + "','" + ativo + "','" + stock + "')";

    try {
        int done = stmt.executeUpdate(inserirArtigo);

    } catch (SQLException ex) {
        Logger.getLogger(ConfArtigo.class.getName()).log(Level.SEVERE, null, ex);
    }
    initComponents();
    System.out.println("Dados inseridos com sucesso!!");
    jTabConfArtigo.setEnabledAt(1, true);
    jTabConfArtigo.setSelectedIndex(1);
}   

The program runs until the System.out.println("Dados inseridos com sucesso") but does not change to the tab next, does anyone know why ?

  • I believe you’re using a JTabbedPane,right? What does the initCOmponents() there?

  • Could you post the code that mounts the window? If you can’t, at least show us how to jTabConfArtigo is created, please.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.