Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Add more components from JFrame Form

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Add more components from JFrame Form

    This is the first time I am trying to use the drag and drop with JFrame Form in Java. I am trying to make a GUI that are going to create new components when the user are clicking a button.
    In my GUI I have some labels and a lot of checkboxes. The GUI is going to look like a bingo game. The user could enter hove many different of bingo bricks he would play. He could 100 if he so want. The program should then take the numbers the user write and then generate 100 bingo bricks between each other on a raw. The problem is that I canīt generate any SWING components by hardcoding when I use JFrame Form. I have tried to make som example components just to see if I can see it on the Frame but I canīt get any.
    I am trying to use the same way Iīve do when I hand code Swing components but I canīt get it to work with my JFrame Form.
    I enclose al my JFram Form code just so you can get an idea hove my thought about it is.

    Her is the place where I am trying to write the code:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            generateRader();
        }                                        
     
        private void generateRader ()
        {
     
        }

    And here is the full code (Just to see hove it looks):
    public class GUI extends javax.swing.JFrame {
     
     
        public GUI() {
            initComponents();
        }
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            buttonGroup1 = new javax.swing.ButtonGroup();
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            jLabel8 = new javax.swing.JLabel();
            jLabel9 = new javax.swing.JLabel();
            jLabel10 = new javax.swing.JLabel();
            jLabel11 = new javax.swing.JLabel();
            jLabel12 = new javax.swing.JLabel();
            jLabel13 = new javax.swing.JLabel();
            jCheckBox1_1 = new javax.swing.JCheckBox();
            jCheckBox1_X = new javax.swing.JCheckBox();
            jCheckBox1_2 = new javax.swing.JCheckBox();
            jCheckBox2_X = new javax.swing.JCheckBox();
            jCheckBox2_2 = new javax.swing.JCheckBox();
            jCheckBox2_1 = new javax.swing.JCheckBox();
            jCheckBox3_1 = new javax.swing.JCheckBox();
            jCheckBox3_X = new javax.swing.JCheckBox();
            jCheckBox3_2 = new javax.swing.JCheckBox();
            jCheckBox4_1 = new javax.swing.JCheckBox();
            jCheckBox4_X = new javax.swing.JCheckBox();
            jCheckBox4_2 = new javax.swing.JCheckBox();
            jCheckBox5_1 = new javax.swing.JCheckBox();
            jCheckBox5_X = new javax.swing.JCheckBox();
            jCheckBox5_2 = new javax.swing.JCheckBox();
            jCheckBox6_1 = new javax.swing.JCheckBox();
            jCheckBox6_X = new javax.swing.JCheckBox();
            jCheckBox6_2 = new javax.swing.JCheckBox();
            jCheckBox7_1 = new javax.swing.JCheckBox();
            jCheckBox7_X = new javax.swing.JCheckBox();
            jCheckBox7_2 = new javax.swing.JCheckBox();
            jCheckBox8_1 = new javax.swing.JCheckBox();
            jCheckBox8_X = new javax.swing.JCheckBox();
            jCheckBox8_2 = new javax.swing.JCheckBox();
            jCheckBox9_1 = new javax.swing.JCheckBox();
            jCheckBox9_X = new javax.swing.JCheckBox();
            jCheckBox9_2 = new javax.swing.JCheckBox();
            jCheckBox10_1 = new javax.swing.JCheckBox();
            jCheckBox10_X = new javax.swing.JCheckBox();
            jCheckBox10_2 = new javax.swing.JCheckBox();
            jCheckBox11_1 = new javax.swing.JCheckBox();
            jCheckBox11_X = new javax.swing.JCheckBox();
            jCheckBox11_2 = new javax.swing.JCheckBox();
            jCheckBox12_1 = new javax.swing.JCheckBox();
            jCheckBox12_X = new javax.swing.JCheckBox();
            jCheckBox12_2 = new javax.swing.JCheckBox();
            jCheckBox13_1 = new javax.swing.JCheckBox();
            jCheckBox13_X = new javax.swing.JCheckBox();
            jCheckBox13_2 = new javax.swing.JCheckBox();
            jLabel14 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jCheckBox1_1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox1_1ActionPerformed(evt);
                }
            });
     
            jCheckBox1_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox1_XActionPerformed(evt);
                }
            });
     
            jCheckBox1_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox1_2ActionPerformed(evt);
                }
            });
     
            jCheckBox2_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox2_XActionPerformed(evt);
                }
            });
     
            jCheckBox2_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox2_2ActionPerformed(evt);
                }
            });
     
            jCheckBox3_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox3_XActionPerformed(evt);
                }
            });
     
            jCheckBox3_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox3_2ActionPerformed(evt);
                }
            });
     
            jCheckBox4_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox4_XActionPerformed(evt);
                }
            });
     
            jCheckBox4_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox4_2ActionPerformed(evt);
                }
            });
     
            jCheckBox5_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox5_XActionPerformed(evt);
                }
            });
     
            jCheckBox5_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox5_2ActionPerformed(evt);
                }
            });
     
            jCheckBox6_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox6_XActionPerformed(evt);
                }
            });
     
            jCheckBox6_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox6_2ActionPerformed(evt);
                }
            });
     
            jCheckBox7_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox7_XActionPerformed(evt);
                }
            });
     
            jCheckBox7_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox7_2ActionPerformed(evt);
                }
            });
     
            jCheckBox8_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox8_XActionPerformed(evt);
                }
            });
     
            jCheckBox8_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox8_2ActionPerformed(evt);
                }
            });
     
            jCheckBox9_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox9_XActionPerformed(evt);
                }
            });
     
            jCheckBox9_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox9_2ActionPerformed(evt);
                }
            });
     
            jCheckBox10_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox10_XActionPerformed(evt);
                }
            });
     
            jCheckBox10_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox10_2ActionPerformed(evt);
                }
            });
     
            jCheckBox11_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox11_XActionPerformed(evt);
                }
            });
     
            jCheckBox11_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox11_2ActionPerformed(evt);
                }
            });
     
            jCheckBox12_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox12_XActionPerformed(evt);
                }
            });
     
            jCheckBox12_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox12_2ActionPerformed(evt);
                }
            });
     
            jCheckBox13_X.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox13_XActionPerformed(evt);
                }
            });
     
            jCheckBox13_2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jCheckBox13_2ActionPerformed(evt);
                }
            });
     
            jLabel14.setText("  1     X     2");
     
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jTextField1.setText("jTextField1");
     
            org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(jPanel1Layout.createSequentialGroup()
                            .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jLabel1)
                                .add(jLabel2)
                                .add(jLabel3)
                                .add(jLabel4)
                                .add(jLabel5)
                                .add(jLabel6)
                                .add(jLabel7)
                                .add(jLabel8)
                                .add(jLabel9)
                                .add(jLabel10)
                                .add(jLabel11)
                                .add(jLabel12)
                                .add(jLabel13))
                            .add(38, 38, 38)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox13_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox13_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox13_2))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox11_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox11_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox11_2))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox10_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox10_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox10_2))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox9_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox9_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox9_2))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox8_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox8_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox8_2))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox7_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox7_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox7_2))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox6_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox6_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox6_2))
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jPanel1Layout.createSequentialGroup()
                                                .add(jCheckBox5_1)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox5_X)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox5_2))
                                            .add(jPanel1Layout.createSequentialGroup()
                                                .add(jCheckBox3_1)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox3_X)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox3_2))
                                            .add(jPanel1Layout.createSequentialGroup()
                                                .add(jCheckBox2_1)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox2_X)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox2_2))
                                            .add(jLabel14)
                                            .add(jPanel1Layout.createSequentialGroup()
                                                .add(jCheckBox1_1)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox1_X)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jCheckBox1_2)))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jCheckBox4_1)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jCheckBox4_X)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jCheckBox4_2)))
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(jCheckBox12_1)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox12_X)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jCheckBox12_2)))))
                    .add(18, 18, 18)
                    .add(jButton1)
                    .addContainerGap(143, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(41, 41, 41)
                    .add(jLabel14)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(jLabel1)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jCheckBox1_1)
                            .add(jCheckBox1_2)
                            .add(jCheckBox1_X)))
                    .add(4, 4, 4)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel2)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jCheckBox2_2)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jCheckBox2_X)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jCheckBox2_1))
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(8, 8, 8)
                            .add(jLabel3))
                        .add(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jCheckBox3_2)
                                .add(jCheckBox3_X)
                                .add(jCheckBox3_1))))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jLabel4)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jCheckBox4_2)
                            .add(jCheckBox4_X)
                            .add(jCheckBox4_1)))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(jLabel5)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jLabel6)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 61, Short.MAX_VALUE)
                            .add(jLabel7))
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jCheckBox5_2)
                                .add(jCheckBox5_X)
                                .add(jCheckBox5_1))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jCheckBox6_2)
                                .add(jCheckBox6_X)
                                .add(jCheckBox6_1))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jCheckBox7_2)
                                .add(jCheckBox7_X)
                                .add(jCheckBox7_1))))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(jLabel8)
                        .add(jCheckBox8_2)
                        .add(jCheckBox8_X)
                        .add(jCheckBox8_1))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(jLabel9)
                        .add(jCheckBox9_2)
                        .add(jCheckBox9_X)
                        .add(jCheckBox9_1))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jLabel10)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jCheckBox10_2)
                            .add(jCheckBox10_X)
                            .add(jCheckBox10_1)))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jLabel11)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jCheckBox11_2)
                            .add(jCheckBox11_X)
                            .add(jCheckBox11_1)))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(jLabel12)
                            .add(12, 12, 12)
                            .add(jLabel13)
                            .add(24, 24, 24))
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jCheckBox12_2)
                                .add(jCheckBox12_X)
                                .add(jCheckBox12_1))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jCheckBox13_2)
                                .add(jCheckBox13_X)
                                .add(jCheckBox13_1))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                    .add(8, 8, 8)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jButton1))
                    .addContainerGap())
            );
     
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
     
            pack();
        }// </editor-fold>                        
     
        private void jCheckBox1_1ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox1_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox1_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox2_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox2_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox3_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox3_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox4_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox4_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox5_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox5_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox6_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox6_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox7_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox7_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox8_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox8_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox9_XActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox9_2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jCheckBox10_XActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void jCheckBox10_2ActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void jCheckBox11_XActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void jCheckBox11_2ActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void jCheckBox12_XActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void jCheckBox12_2ActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void jCheckBox13_XActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
    }                                             
     
        private void jCheckBox13_2ActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
    }                                             
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            generateRader();
        }                                        
     
        private void generateRader ()
        {
     
        }
     
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
     
                public void run() {
                    new GUI().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.ButtonGroup buttonGroup1;
        private javax.swing.JButton jButton1;
        private javax.swing.JCheckBox jCheckBox10_1;
        private javax.swing.JCheckBox jCheckBox10_2;
        private javax.swing.JCheckBox jCheckBox10_X;
        private javax.swing.JCheckBox jCheckBox11_1;
        private javax.swing.JCheckBox jCheckBox11_2;
        private javax.swing.JCheckBox jCheckBox11_X;
        private javax.swing.JCheckBox jCheckBox12_1;
        private javax.swing.JCheckBox jCheckBox12_2;
        private javax.swing.JCheckBox jCheckBox12_X;
        private javax.swing.JCheckBox jCheckBox13_1;
        private javax.swing.JCheckBox jCheckBox13_2;
        private javax.swing.JCheckBox jCheckBox13_X;
        private javax.swing.JCheckBox jCheckBox1_1;
        private javax.swing.JCheckBox jCheckBox1_2;
        private javax.swing.JCheckBox jCheckBox1_X;
        private javax.swing.JCheckBox jCheckBox2_1;
        private javax.swing.JCheckBox jCheckBox2_2;
        private javax.swing.JCheckBox jCheckBox2_X;
        private javax.swing.JCheckBox jCheckBox3_1;
        private javax.swing.JCheckBox jCheckBox3_2;
        private javax.swing.JCheckBox jCheckBox3_X;
        private javax.swing.JCheckBox jCheckBox4_1;
        private javax.swing.JCheckBox jCheckBox4_2;
        private javax.swing.JCheckBox jCheckBox4_X;
        private javax.swing.JCheckBox jCheckBox5_1;
        private javax.swing.JCheckBox jCheckBox5_2;
        private javax.swing.JCheckBox jCheckBox5_X;
        private javax.swing.JCheckBox jCheckBox6_1;
        private javax.swing.JCheckBox jCheckBox6_2;
        private javax.swing.JCheckBox jCheckBox6_X;
        private javax.swing.JCheckBox jCheckBox7_1;
        private javax.swing.JCheckBox jCheckBox7_2;
        private javax.swing.JCheckBox jCheckBox7_X;
        private javax.swing.JCheckBox jCheckBox8_1;
        private javax.swing.JCheckBox jCheckBox8_2;
        private javax.swing.JCheckBox jCheckBox8_X;
        private javax.swing.JCheckBox jCheckBox9_1;
        private javax.swing.JCheckBox jCheckBox9_2;
        private javax.swing.JCheckBox jCheckBox9_X;
        public static javax.swing.JLabel jLabel1;
        public static javax.swing.JLabel jLabel10;
        public static javax.swing.JLabel jLabel11;
        public static javax.swing.JLabel jLabel12;
        public static javax.swing.JLabel jLabel13;
        private javax.swing.JLabel jLabel14;
        public static javax.swing.JLabel jLabel2;
        public static javax.swing.JLabel jLabel3;
        public static javax.swing.JLabel jLabel4;
        public static javax.swing.JLabel jLabel5;
        public static javax.swing.JLabel jLabel6;
        public static javax.swing.JLabel jLabel7;
        public static javax.swing.JLabel jLabel8;
        public static javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                   
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Add more components from JFrame Form

    What do you mean when you say you "can't get it to work"? What did you expect to happen? What happened instead?

    Also, that's way too much code for anybody else to look at. Boil your problem down to an SSCCE, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Add more components from JFrame Form

    Sorry for the length of my code. I actually get a solution at my problem yesterday. But I have a following problem with my checkboxes.
    The program I am creating are going to show a sort of a bingo game. The user start to choose hove man bingo bricks he wanna play (The bingo brick look like the following picture: ImageShack&#174; - Online Photo and Video Hosting).
    The user should have the ability to enter the checkboxes by here self or the user could randomize all the bricks checkboxes. If the user has marked one check box in one of the bricks and then wanīt to randomize the rest of them then the checkbox that the user has marked shall be marked, and all the others should randomize.
    My question is hove I could make such randomize with just checkboxes?

    In my code example I only show you six different checkboxes, as you can see in the picture it is a lot of more of them. But I am using exactly the same code for every checkboxes in the program. Itīs just to hold down the amount of code. This is all the code I use in the class but for my program I have duplicate it some more times.


    public class testGUI extends JPanel {
     
        CheckBoxListener myListener = null;
        JCheckBox box1_1;
        JCheckBox box1_X;
        JCheckBox box1_2;
        JCheckBox box2_1;
        JCheckBox box2_X;
        JCheckBox box2_2;
     
        public testGUI() {
     
            setSize(170, 350);
            myListener = new CheckBoxListener();
     
            box1_1 = new JCheckBox("");
            box1_1.addItemListener(myListener);
            box1_X = new JCheckBox("");
            box1_X.addItemListener(myListener);
            box1_2 = new JCheckBox("");
            box1_2.addItemListener(myListener);
     
            box2_1 = new JCheckBox("");
            box2_1.addItemListener(myListener);
            box2_X = new JCheckBox("");
            box2_X.addItemListener(myListener);
            box2_2 = new JCheckBox("");
            box2_2.addItemListener(myListener);
     
     
            super.setBorder(new TitledBorder("1      X      2"));
            super.setLayout(new GridLayout(13, 3));
     
            super.add(box1_1);
            super.add(box1_X);
            super.add(box1_2);
     
            super.add(box2_1);
            super.add(box2_X);
            super.add(box2_2);
     
     
        }
     
        class CheckBoxListener implements ItemListener {
     
            List<Integer> list = new LinkedList<Integer>();
     
     
        @Override
            public void itemStateChanged(ItemEvent e) {
     
                Object source = e.getSource();
                if (source == box1_1) {
                    if (box1_1.isSelected()) {
                        list.add(11);
                        box1_X.setVisible(false);
                        box1_2.setVisible(false);
                    } else {
                        list.remove(list.equals(11));
                        box1_X.setVisible(true);
                        box1_2.setVisible(true);
                    }
                }
     
                if (source == box1_X) {
                    if (box1_X.isSelected()) {
                        list.add(12);
                        box1_1.setVisible(false);
                        box1_2.setVisible(false);
                    } else {
                        list.remove(list.equals(12));
                        box1_1.setVisible(true);
                        box1_2.setVisible(true);
                    }
                }
     
                if (source == box1_2) {
                    if (box1_2.isSelected()) {
                        list.add(13);
                        box1_X.setVisible(false);
                        box1_1.setVisible(false);
                    } else {
                        list.remove(list.equals(13));
                        box1_X.setVisible(true);
                        box1_1.setVisible(true);
                    }
                }
     
     
                if (source == box2_1) {
                    if (box2_1.isSelected()) {
                        list.add(21);
                        box2_X.setVisible(false);
                        box2_2.setVisible(false);
                    } else {
                        list.remove(list.equals(21));
                        box2_X.setVisible(true);
                        box2_2.setVisible(true);
                    }
                }
     
                if (source == box2_X) {
                    if (box2_X.isSelected()) {
                        list.add(22);
                        box2_1.setVisible(false);
                        box2_2.setVisible(false);
                    } else {
                        list.remove(list.equals(22));
                        box2_1.setVisible(true);
                        box2_2.setVisible(true);
                    }
                }
     
                if (source == box2_2) {
                    if (box2_2.isSelected()) {
                        list.add(23);
                        box2_X.setVisible(false);
                        box2_1.setVisible(false);
                    } else {
                        list.remove(list.equals(23));
                        box2_X.setVisible(true);
                        box2_1.setVisible(true);
                    }
                }
    }

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Add more components from JFrame Form

    Chances are you could probably minimize your code, and solve your problem, if you used an ArrayList of JCheckBoxes. Then you could simply iterate over the list to initialize them, and to randomize them.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Open JFrame Form With Button
    By cardamis in forum AWT / Java Swing
    Replies: 2
    Last Post: April 12th, 2011, 04:18 AM
  2. Interaction between components.
    By SyntheticD in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 9th, 2011, 07:32 PM
  3. Getting Size of Components
    By aussiemcgr in forum AWT / Java Swing
    Replies: 3
    Last Post: July 26th, 2010, 04:41 PM
  4. Java Swing :Back Button from one form to another form
    By srinivasan_253642 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 26th, 2009, 09:51 AM
  5. Change JFrame components problem
    By bruno88 in forum AWT / Java Swing
    Replies: 0
    Last Post: June 30th, 2009, 02:25 PM