Results 1 to 2 of 2
  1. #1
    lima_bonnel is offline Member
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Default HELP[<<Refreshing mainForm jTable from another jframe!!>>|]

    OK guys, i have this problem, i am creating a program and the starting form has a jTable with mySQL data, then i have a button in this jframe to open another jframe, in this one i want to fill up a client registration and when a press the saving button i wanted the Jtable from the first jframe to refresh! i tried everything...repaint..invalidate,validate! the only thing that works is to make the damn form to dispose and the create a new object, and that is NOT what a want to do,lol. here's my code,sorry that variables are in portuguese:

    Java Code:
    public class painelPrincipal extends javax.swing.JFrame {
    
    public painelPrincipal() {
            initComponents();
            clientes=new conexao();
            clientes.conecta();
            clientes.executeSQL("SELECT * FROM clientesvendedores");
            
            //method that fills jtable
            preencherJTable1();
        }
    
    //button that pops up the client registration im passing "this" to be able to access the methods of this frame from the other
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            new regClientesVendedores(this).setVisible(true);
        } 
    
    public void preencherJTable1()
        {
            jTable1.removeAll();
            jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(170);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(30);
            jTable1.getColumnModel().getColumn(3).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(4).setPreferredWidth(20);
            jTable1.getColumnModel().getColumn(5).setPreferredWidth(20);
            jTable1.getColumnModel().getColumn(6).setPreferredWidth(20);
            
            DefaultTableModel modelo =(DefaultTableModel)jTable1.getModel();
            modelo.setNumRows(0);
             
            try 
            {
                clientes.resultset.first();
                modelo.addRow(new Object[]{clientes.resultset.getString("cod"),clientes.resultset.getString("nome"),clientes.resultset.getString("telemovel"),
                clientes.resultset.getString("refimovel"),clientes.resultset.getString("localidadeimovel"),clientes.resultset.getString("Placa"),
                clientes.resultset.getString("Exclusividade")});
                while (clientes.resultset.next()) {
                    modelo.addRow(new Object[]{clientes.resultset.getString("cod"),clientes.resultset.getString("nome"),clientes.resultset.getString("cartaocidadao"),
                clientes.resultset.getString("refimovel"),clientes.resultset.getString("localidadeimovel"),clientes.resultset.getString("Placa"),
                clientes.resultset.getString("Exclusividade")});      
                }
                clientes.resultset.first();
            } 
            catch (SQLException erro)
            {
                JOptionPane.showMessageDialog(null, "Não foi possível carregar os dados: "+erro);
            }
        }
    ok now the second one!
    Java Code:
    public class regClientesVendedores extends javax.swing.JFrame {
    
        conexao con_cvendedores;
        static painelPrincipal pp;
        /**
         * Creates new form regClientesCompradores
         */
    
        public regClientesVendedores(painelPrincipal x) {
            initComponents();
            con_cvendedores=new conexao();
            con_cvendedores.conecta();
            con_cvendedores.executeSQL("SELECT * FROM clientesvendedores");
            pp=x; //x is the mainframe
        
    }
    //saving button HERE I WANT TO REFRESH JTABLE FROM FIRST FORM!!
     private void botaoGravarActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            //falta ref imovel
            String placa="Não";
            String exclusividade="Não";
            if (jCheckBoxPlaca.isSelected()) {
                placa="Sim";
            }
            if (jCheckBoxExclusividade.isSelected()) {
                exclusividade="Sim";
            }
            String sqlinsert="insert into clientesvendedores(nome,cartaocidadao,contribuinte,"
                    + "morada,codpostal,localidade,concelho,estadocivil,datanascimento,"
                    + "nacionalidade,naturalidade,tipoimovel,tipologiaimovel,"
                    + "precoimovel,ruaimovel,codpostalimovel,localidadeimovel,concelhoimovel,"
                    + "Placa,Exclusividade,telemovel,refimovel) values('"+campoNome.getText()+"','"+campoCartaoCidadao.getText()+"','"
                    + campoContribuinte.getText()+"','"+campoMorada.getText()+"','"+campoCodigoPostal.getText()+"','"
                    +campoLocalidade.getText()+"','"+campoConcelho.getText()+"','"+jComboEstadoCivil.getSelectedItem()+"','"
                    +campoDataNascimento.getText()+"','"+campoNacionalidade.getText()+"','"+campoNaturalidade.getText()+"','" 
                    +jcomboTipoImovel.getSelectedItem()+"','"+campoTipologia.getText()+"','"+campoPreco.getText()+"','"
                    +campoRua.getText()+"','"+campoCodigoPostalImovel.getText()+"','"+campoLocalidadeImovel.getText()+"','"
                    +campoConcelhoImovel.getText()+"','"+placa+"','"+exclusividade+"','"+campoTelefone.getText()+"','"+camporefimovel.getText()+"')";
                    try
                    {
                        con_cvendedores.statement.executeUpdate(sqlinsert);
                        //here i'm trying to make what i want, any ideas? i tried everything!
                        pp.preencherJTable1();
                        pp.invalidate();
                        pp.validate();
                        JOptionPane.showMessageDialog(null, "Guardado com sucesso");
                    }
                    catch(SQLException erro)
                    {
                        JOptionPane.showMessageDialog(null, "Não foi possível guardar: "+erro);
                    }
        }
    }
    again..sorry code's in portuguese, i think u an understand

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,303
    Rep Power
    20

    Default Re: HELP[<<Refreshing mainForm jTable from another jframe!!>>|]

    Moved from Forum Guides

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Need Help in Jtable to Jframe...
    By rexonlescano1 in forum AWT / Swing
    Replies: 5
    Last Post: 10-12-2011, 08:38 AM
  2. Data not refreshing in Jtable
    By pink123 in forum AWT / Swing
    Replies: 5
    Last Post: 03-22-2011, 09:43 PM
  3. Refreshing Jtable once again...
    By Norther in forum AWT / Swing
    Replies: 2
    Last Post: 06-29-2010, 07:46 PM
  4. [SOLVED] JTable and JFrame problem
    By nehaa in forum AWT / Swing
    Replies: 5
    Last Post: 05-06-2009, 04:25 PM
  5. Jframe In Jtable cell
    By Clarion in forum AWT / Swing
    Replies: 4
    Last Post: 06-23-2008, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •