Page 1 of 3 123 LastLast
Results 1 to 20 of 52
Like Tree5Likes

Thread: Trouble in two jFrame, jButton and JTable

  1. #1
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Trouble in two jFrame, jButton and JTable

    I have two jFrame, on the first one i have JTable. and the second one i have labels, text field and button(name add). Is it possible that when I click add the information that i type will be add in jtable.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    Yes. You need to post the code and ask some questions about the problems you are having.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    DefaultTableModel dfmodel = (DefaultTableModel) tStudents.getModel();
    model.addRow(new Object[]{fStudentno.getText(),fGivenname.getText(),fSurnam e.getText(),fCourse.getText(),fYear.getText(),fSec tion.getText()});


    the tStudents is the name of the table from another jframe but their is something error in tStudents
    Last edited by monching; 09-24-2014 at 04:32 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    Please post real code that can be compiled and executed for testing. Not just bits and pieces.

    Be sure to wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    Sorry sir

    Java Code:
    import javax.swing.table.DefaultTableModel;
    
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author monching
     */
    public class Registration extends javax.swing.JFrame {
    
        /**
         * Creates new form Registration
         */
        public Registration() {
            initComponents();
        }
    
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            REGISTRATION = new javax.swing.JLabel();
            lStudentno = new javax.swing.JLabel();
            fStudentno = new javax.swing.JTextField();
            lGivename = new javax.swing.JLabel();
            fGivenname = new javax.swing.JTextField();
            lMiddlename = new javax.swing.JLabel();
            fMiddlename = new javax.swing.JTextField();
            lSurname = new javax.swing.JLabel();
            fSurname = new javax.swing.JTextField();
            lCourse = new javax.swing.JLabel();
            fCourse = new javax.swing.JTextField();
            lYear = new javax.swing.JLabel();
            fYear = new javax.swing.JTextField();
            lSection = new javax.swing.JLabel();
            fSection = new javax.swing.JTextField();
            bAdd = new javax.swing.JButton();
            bExit = new javax.swing.JButton();
            lContactno = new javax.swing.JLabel();
            fContactno = new javax.swing.JTextField();
            lEmail = new javax.swing.JLabel();
            fEmail = new javax.swing.JTextField();
            CLEAR = new javax.swing.JButton();
            Reminder = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            REGISTRATION.setFont(new java.awt.Font("Courier New", 1, 36)); // NOI18N
            REGISTRATION.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            REGISTRATION.setText("REGISTRATION");
    
            lStudentno.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lStudentno.setText("Student no.         :");
    
            lGivename.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lGivename.setText("Given Name        :");
    
            lMiddlename.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lMiddlename.setText("Middle Name       :");
    
            lSurname.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lSurname.setText("Surname             :");
    
            lCourse.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lCourse.setText("Course                :");
    
            fCourse.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    fCourseActionPerformed(evt);
                }
            });
    
            lYear.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lYear.setText("Year                   :");
    
            lSection.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lSection.setText("Section               :");
    
            bAdd.setText("ADD");
            bAdd.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bAddActionPerformed(evt);
                }
            });
    
            bExit.setText("EXIT");
            bExit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bExitActionPerformed(evt);
                }
            });
    
            lContactno.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lContactno.setText("Contact no.         :");
    
            fContactno.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    fContactnoActionPerformed(evt);
                }
            });
    
            lEmail.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            lEmail.setText("E-mail                 :");
    
            fEmail.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    fEmailActionPerformed(evt);
                }
            });
    
            CLEAR.setText("CLEAR");
            CLEAR.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    CLEARActionPerformed(evt);
                }
            });
    
            Reminder.setFont(new java.awt.Font("Gungsuh", 1, 18)); // NOI18N
            Reminder.setForeground(new java.awt.Color(255, 0, 51));
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(68, 68, 68)
                            .addComponent(REGISTRATION))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(lStudentno)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(fStudentno, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(lGivename)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(fGivenname, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(lMiddlename)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(fMiddlename, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(lSurname)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(fSurname, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(bAdd)
                                        .addComponent(lSection))
                                    .addGap(27, 27, 27)
                                    .addComponent(CLEAR)
                                    .addGap(41, 41, 41)
                                    .addComponent(bExit))
                                .addComponent(lCourse)
                                .addComponent(lYear)))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lContactno)
                                .addComponent(lEmail))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(fEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(fSection, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(fContactno, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(fYear, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(fCourse, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(0, 51, Short.MAX_VALUE)
                    .addComponent(Reminder, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(42, 42, 42))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addComponent(REGISTRATION, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lStudentno)
                        .addComponent(fStudentno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lGivename)
                        .addComponent(fGivenname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lMiddlename)
                        .addComponent(fMiddlename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lSurname)
                        .addComponent(fSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lCourse)
                        .addComponent(fCourse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lYear)
                        .addComponent(fYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lSection)
                        .addComponent(fSection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lContactno)
                        .addComponent(fContactno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lEmail)
                        .addComponent(fEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(Reminder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(bAdd)
                        .addComponent(bExit)
                        .addComponent(CLEAR))
                    .addGap(30, 30, 30))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void bAddActionPerformed(java.awt.event.ActionEvent evt) {                                     
            DefaultTableModel model = (DefaultTableModel) tStudents.getModel();
            model.addRow(new Object[]{fStudentno.getText(),fGivenname.getText(),fSurname.getText(),fCourse.getText(),fYear.getText(),fSection.getText()});
        }                                    
    
        private void bExitActionPerformed(java.awt.event.ActionEvent evt) {                                      
            System.exit(0);
        }                                     
    
        private void fContactnoActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
        }                                          
    
        private void fEmailActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
        }                                      
    
        private void CLEARActionPerformed(java.awt.event.ActionEvent evt) {                                      
            fStudentno.setText("");
            fGivenname.setText("");
            fMiddlename.setText("");
            fSurname.setText("");
            fCourse.setText("");
            fYear.setText("");
            fSection.setText("");
            fContactno.setText("");
            fEmail.setText("");
        }                                     
    
        private void fCourseActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
        }                                       
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Registration().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton CLEAR;
        private javax.swing.JLabel REGISTRATION;
        private javax.swing.JLabel Reminder;
        private javax.swing.JButton bAdd;
        private javax.swing.JButton bExit;
        private javax.swing.JTextField fContactno;
        private javax.swing.JTextField fCourse;
        private javax.swing.JTextField fEmail;
        private javax.swing.JTextField fGivenname;
        private javax.swing.JTextField fMiddlename;
        private javax.swing.JTextField fSection;
        private javax.swing.JTextField fStudentno;
        private javax.swing.JTextField fSurname;
        private javax.swing.JTextField fYear;
        private javax.swing.JLabel lContactno;
        private javax.swing.JLabel lCourse;
        private javax.swing.JLabel lEmail;
        private javax.swing.JLabel lGivename;
        private javax.swing.JLabel lMiddlename;
        private javax.swing.JLabel lSection;
        private javax.swing.JLabel lStudentno;
        private javax.swing.JLabel lSurname;
        private javax.swing.JLabel lYear;
        // End of variables declaration                   
    }

  6. #6
    guadalcanal is offline Member
    Join Date
    Sep 2014
    Posts
    6
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    Typically when asking for help with your code it's more useful if you make a short example program that highlights the problem you're having. Very few people have time to search through 300+ lines of code looking for your problem.

  7. #7
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    Sorry again sir because I just made it in netbeans swing. here's the short version

    Java Code:
    import javax.swing.table.DefaultTableModel;
    
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author monching
     */
    public class Registration extends javax.swing.JFrame {
    
        /**
         * Creates new form Registration
         */
        public Registration() {
            initComponents();
        }
    
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
                      
    
        private void bAddActionPerformed(java.awt.event.ActionEvent evt) {                                     
            DefaultTableModel model = (DefaultTableModel) tStudents.getModel();
            model.addRow(new Object[]{fStudentno.getText(),fGivenname.getText(),fSurname.getText(),fCourse.getText(),fYear.getText(),fSection.getText()});
        }                                    
    
        private void bExitActionPerformed(java.awt.event.ActionEvent evt) {                                      
            System.exit(0);
        }                                     
    
        private void fContactnoActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
        }                                          
    
        private void fEmailActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
        }                                      
    
        private void CLEARActionPerformed(java.awt.event.ActionEvent evt) {                                      
            fStudentno.setText("");
            fGivenname.setText("");
            fMiddlename.setText("");
            fSurname.setText("");
            fCourse.setText("");
            fYear.setText("");
            fSection.setText("");
            fContactno.setText("");
            fEmail.setText("");
        }                                     
    
        private void fCourseActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
        }                                       
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Registration().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton CLEAR;
        private javax.swing.JLabel REGISTRATION;
        private javax.swing.JLabel Reminder;
        private javax.swing.JButton bAdd;
        private javax.swing.JButton bExit;
        private javax.swing.JTextField fContactno;
        private javax.swing.JTextField fCourse;
        private javax.swing.JTextField fEmail;
        private javax.swing.JTextField fGivenname;
        private javax.swing.JTextField fMiddlename;
        private javax.swing.JTextField fSection;
        private javax.swing.JTextField fStudentno;
        private javax.swing.JTextField fSurname;
        private javax.swing.JTextField fYear;
        private javax.swing.JLabel lContactno;
        private javax.swing.JLabel lCourse;
        private javax.swing.JLabel lEmail;
        private javax.swing.JLabel lGivename;
        private javax.swing.JLabel lMiddlename;
        private javax.swing.JLabel lSection;
        private javax.swing.JLabel lStudentno;
        private javax.swing.JLabel lSurname;
        private javax.swing.JLabel lYear;
        // End of variables declaration                   
    }

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Trouble in two jFrame, jButton and JTable

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

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    The posted code does not compile. It has missing parts.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    sir try the first one i posted. i created that in netbeans ide 7.4 with jframe sir.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    Can you make a small complete program that compiles, executes and shows the problem.
    The second one is about the right size, the first one is too large. See post#6
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    its too hard sir because i just created in jframe drag and drop, the only problem is the code

    Java Code:
    private void bAddActionPerformed(java.awt.event.ActionEvent evt) {                                     
            DefaultTableModel model = (DefaultTableModel) tStudents.getModel();
            model.addRow(new Object[]{fStudentno.getText(),fGivenname.getText(),fSurname.getText(),fCourse.getText(),fYear.getText(),fSection.getText()});
        }
    here's the code for the add button. the error is the tStudents because it's not exist in the jframe because it's separated jframe
    Last edited by monching; 09-25-2014 at 12:37 AM.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    To access data in another class, you need a reference to the instance of the class with the data so you can call its methods:
    someVariable = aRefToClassWithData.theMethodToCallToGetDatal();
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    Is it the same with the other jFrame

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    It's the same with any class.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    thanks sir. where do i put the code? is in the button add?
    Last edited by monching; 09-25-2014 at 08:42 AM.

  17. #17
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    where do i put the code?
    Post the code here.
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    ok sir here's the code and screenshots
    Trouble in two jFrame, jButton and JTable-1.png
    Trouble in two jFrame, jButton and JTable-2.png
    code for the first one
    Java Code:
    import javax.swing.table.DefaultTableModel;
    
    public class Registration extends javax.swing.JFrame {
    
        /**
         * Creates new form Registration
         */
        public Registration() {
            initComponents();
        }
     @SuppressWarnings("unchecked")
    
        private void bAddActionPerformed(java.awt.event.ActionEvent evt) {                                     
            DefaultTableModel model = (DefaultTableModel) tStudents.getModel();
            model.addRow(new Object[]{fStudentno.getText(),fGivenname.getText(),fSurname.getText(),fAddress.getText(),fCivilstatus.getText(),fNationality.getText()});
        }                                    
    
        private void bExitActionPerformed(java.awt.event.ActionEvent evt) {                                      
            System.exit(0);
        }                                     
    
        private void fContactnoActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
        }                                          
    
        private void fEmailActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
        }                                      
    
        private void CLEARActionPerformed(java.awt.event.ActionEvent evt) {                                      
            fStudentno.setText("");
            fGivenname.setText("");
            fMiddlename.setText("");
            fSurname.setText("");
            fAddress.setText("");
            fCivilstatus.setText("");
            fNationality.setText("");
            fContactno.setText("");
            fEmail.setText("");
        }                                     
    
        private void fAddressActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
        }                                        
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Registration().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton CLEAR;
        private javax.swing.JLabel REGISTRATION;
        private javax.swing.JLabel Reminder;
        private javax.swing.JButton bAdd;
        private javax.swing.JButton bExit;
        private javax.swing.JTextField fAddress;
        private javax.swing.JTextField fCivilstatus;
        private javax.swing.JTextField fContactno;
        private javax.swing.JTextField fEmail;
        private javax.swing.JTextField fGivenname;
        private javax.swing.JTextField fMiddlename;
        private javax.swing.JTextField fNationality;
        private javax.swing.JTextField fSurname;
        private javax.swing.JLabel lAddress;
        private javax.swing.JLabel lCivilstatus;
        private javax.swing.JLabel lContactno;
        private javax.swing.JLabel lEmail;
        private javax.swing.JLabel lGivename;
        private javax.swing.JLabel lMiddlename;
        private javax.swing.JLabel lNationality;
        private javax.swing.JLabel lSurname;
        // End of variables declaration                   
    }

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Trouble in two jFrame, jButton and JTable

    Can you explain what the problem is now?

    The posted code does not compile. It has compiler errors.

    Can you make two small, simple classes with a GUI that shows the problem?
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    monching is offline Member
    Join Date
    Sep 2014
    Posts
    31
    Rep Power
    0

    Default Re: Trouble in two jFrame, jButton and JTable

    the problem is the function of add button that transfer to jtable without opening it. sir where did you compile my code? it's too hard sir because i'm just beginner in swing and i don't know how to write a code for gui why i use drag and drop

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 11-27-2011, 05:18 AM
  2. sos help in jbutton -jtable
    By nor in forum AWT / Swing
    Replies: 2
    Last Post: 01-09-2011, 04:30 AM
  3. Link between two JFrame using JButton
    By Ravi Ranjan in forum NetBeans
    Replies: 2
    Last Post: 06-09-2009, 10:30 PM
  4. Adding JButton to a JTable
    By ting.at.net@hotmail.com in forum AWT / Swing
    Replies: 6
    Last Post: 05-26-2009, 03:37 AM
  5. JButton to display JTable
    By Nemesis777 in forum New To Java
    Replies: 0
    Last Post: 12-08-2008, 12:16 PM

Posting Permissions

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