Results 1 to 2 of 2
  1. #1
    wilnicm is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default My checkbox is not appearing on my jcollapsible panel

    Hi i've been having an issue with my radio button listener.
    I've debugged it and see that its going to the listener. At the listerner i'm
    adding code to add my checkbox component onto my jcollapsible pannel which i'm not seeing being added at all?.
    Do i need to add an extra listerner or something?
    Here is the below code of the short prog i created since it wasn't really working on my overall program in my actual program
    i'd see the text box after i clicked on the panel itself?
    below is my short demo prog.

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JCheckBox;
    
    /*
     * 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 wmarc
     */
    public class radiobtn extends javax.swing.JFrame {
    
        /**
         * Creates new form radiobtn
         */
        
          JCheckBox checkBoxArray[] = new JCheckBox[5];
          
        public radiobtn() {
             
            initComponents();
            createChkboxt();
          radiobtnMth();
            
        }
    
        
        public void createChkboxt(){
              
            checkBoxArray[0] = new JCheckBox("Base Verification that nothing on page changed");
            checkBoxArray[1] = new JCheckBox("Pick a Order");
            checkBoxArray[2] = new JCheckBox("Pick a 2Order");
            checkBoxArray[3] = new JCheckBox("Perform a T");
            checkBoxArray[4] = new JCheckBox("Perform an Ant");   
    
       
    }
        
        
        public void radiobtnMth(){
        
            radiobtns  rb = new radiobtns();
            
        newWMSradiobtn.addActionListener(rb);
        
        
        
        }
        
            public class radiobtns implements ActionListener {
    
            public void actionPerformed(ActionEvent e) {
    
                // Set enabled based on button text (you can use whatever text you prefer)
                if (newWMSradiobtn.isSelected()==true) {
    
    
                    for (int i = 0;
                        i < 5; i++) {
    
                    checkbxpanel.add(checkBoxArray[i]);
                 
    
                }
    
                }
    
            }
    
        }
        
        
        
        
        
        /**
         * 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() {
    
            newWMSradiobtn = new javax.swing.JRadioButton();
            checkbxpanel = new org.jdesktop.swingx.JXCollapsiblePane();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            newWMSradiobtn.setText("newWMS Test");
    
            checkbxpanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Selected Tests"));
    
            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(36, 36, 36)
                            .addComponent(newWMSradiobtn))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(checkbxpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(57, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(63, 63, 63)
                    .addComponent(newWMSradiobtn)
                    .addGap(18, 18, 18)
                    .addComponent(checkbxpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
         * @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(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(radiobtn.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 radiobtn().setVisible(true);
                   
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private org.jdesktop.swingx.JXCollapsiblePane checkbxpanel;
        private javax.swing.JRadioButton newWMSradiobtn;
        // End of variables declaration                   
    }
    Last edited by wilnicm; 07-22-2014 at 07:19 PM. Reason: fixing somthing in code

  2. #2
    wilnicm is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: My checkbox is not appearing on my jcollapsible panel

    Quote Originally Posted by wilnicm View Post
    Hi i've been having an issue with my radio button listener.
    I've debugged it and see that its going to the listener. At the listerner i'm
    adding code to add my checkbox component onto my jcollapsible pannel which i'm not seeing being added at all?.
    Do i need to add an extra listerner or something?
    Here is the below code of the short prog i created since it wasn't really working on my overall program in my actual program
    i'd see the text box after i clicked on the panel itself?
    below is my short demo prog.

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JCheckBox;
    
    /*
     * 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 wmarc
     */
    public class radiobtn extends javax.swing.JFrame {
    
        /**
         * Creates new form radiobtn
         */
        
          JCheckBox checkBoxArray[] = new JCheckBox[5];
          
        public radiobtn() {
             
            initComponents();
            createChkboxt();
          radiobtnMth();
            
        }
    
        
        public void createChkboxt(){
              
            checkBoxArray[0] = new JCheckBox("Base Verification that nothing on page changed");
            checkBoxArray[1] = new JCheckBox("Pick a Order");
            checkBoxArray[2] = new JCheckBox("Pick a 2Order");
            checkBoxArray[3] = new JCheckBox("Perform a T");
            checkBoxArray[4] = new JCheckBox("Perform an Ant");   
    
       
    }
        
        
        public void radiobtnMth(){
        
            radiobtns  rb = new radiobtns();
            
        newWMSradiobtn.addActionListener(rb);
        
        
        
        }
        
            public class radiobtns implements ActionListener {
    
            public void actionPerformed(ActionEvent e) {
    
                // Set enabled based on button text (you can use whatever text you prefer)
                if (newWMSradiobtn.isSelected()==true) {
    
    
                    for (int i = 0;
                        i < 5; i++) {
    
                    checkbxpanel.add(checkBoxArray[i]);
                 
    
                }
    
                }
    
            }
    
        }
        
        
        
        
        
        /**
         * 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() {
    
            newWMSradiobtn = new javax.swing.JRadioButton();
            checkbxpanel = new org.jdesktop.swingx.JXCollapsiblePane();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            newWMSradiobtn.setText("newWMS Test");
    
            checkbxpanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Selected Tests"));
    
            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(36, 36, 36)
                            .addComponent(newWMSradiobtn))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(checkbxpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(57, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(63, 63, 63)
                    .addComponent(newWMSradiobtn)
                    .addGap(18, 18, 18)
                    .addComponent(checkbxpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
         * @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(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(radiobtn.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 radiobtn().setVisible(true);
                   
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private org.jdesktop.swingx.JXCollapsiblePane checkbxpanel;
        private javax.swing.JRadioButton newWMSradiobtn;
        // End of variables declaration                   
    }
    I figured this out. I created a quick demo app and worked my way to the solution.
    Below here is my demo app with my 1 radio button i had to fix some other issues once i added more radio buttons to make
    my it behave the way i wanted so you'll have to do the same. This was done on Netbeans so there is some other unneeded stuff on there that the ide put in there.

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JCheckBox;
    
    /*
     * 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 wmarc
     */
    public class radiobtn extends javax.swing.JFrame {
    
        /**
         * Creates new form radiobtn
         */
        JCheckBox checkBoxArray[] = new JCheckBox[5];
        JCheckBox bb = new JCheckBox("Take that out of there");
    
        public radiobtn() {
    
            initComponents();
            createChkboxt();
          radiobtnMth();
    //        addtopanel();
    
        }
    
        public void createChkboxt() {
    
            checkBoxArray[0] = new JCheckBox("Base Verification that nothing on page changed");
            checkBoxArray[0].setVisible(false);
    
            checkBoxArray[1] = new JCheckBox("Pick a SSKU Order");
            checkBoxArray[1].setVisible(false);
    
            checkBoxArray[2] = new JCheckBox("Pick a CONS Order");
            checkBoxArray[2].setVisible(false);
    
            checkBoxArray[3] = new JCheckBox("Perform a Tweak");
            checkBoxArray[3].setVisible(false);
    
            checkBoxArray[4] = new JCheckBox("Perform an Adjustment");
            checkBoxArray[4].setVisible(false);
        }
    
        public void addtopanel(int myposition) {
    
            for (int i = myposition;
                    i < 5; i++) {
                int b = 5;
    //                 createChkboxt();
                checkbxpanel.add(checkBoxArray[i]);
    
            }
    
        }
    
        public void radiobtnMth() {
    
            radiobtns rb = new radiobtns();
        
            newWMSradiobtn.addActionListener(rb);
      
    //      createChkboxt();
        }
    
       
        
        public class radiobtns implements ActionListener {
    
            public void actionPerformed(ActionEvent e) {
    
                // Set enabled based on button text (you can use whatever text you prefer)
                if (newWMSradiobtn.isSelected() == true) {
    
                        addtopanel(2);
    //                String test = "Hey it works buddy";
    //                System.out.print(test);
                    for (int i = 0;
                            i < 5; i++) {
                        checkBoxArray[i].setVisible(true);
    //                int b = 0;
    ////                 createChkboxt();
    //                
    //                      JCheckBox bb = new JCheckBox("Take that out of there");
    //                 jPanel1.add(bb);
    //                checkbxpanel.add(checkBoxArray[b]);
    //               createChkboxt();
    //                checkBoxArray[i].addItemListener(hc);
                    }
    //                JCheckBox bb = new JCheckBox("Take that out of there");
    //                  
    //                     checkbxpanel.add(bb);
                }
    
               else if (newWMSradiobtn.isSelected() == false) {
                
                for (int i = 0; i <5; i++){
                
                
                checkBoxArray[i].setVisible(false);
                
                
                }
                
                
                
                
                }                       
                
            }
    
        }
    
        /**
         * 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() {
    
            newWMSradiobtn = new javax.swing.JRadioButton();
            checkbxpanel = new org.jdesktop.swingx.JXCollapsiblePane();
            jPanel1 = new javax.swing.JPanel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            newWMSradiobtn.setText("newWMS Test");
    
            checkbxpanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Selected Tests"));
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 502, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 152, Short.MAX_VALUE)
            );
    
            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(48, 48, 48)
                            .addComponent(newWMSradiobtn))
                        .addComponent(checkbxpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 536, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(22, 22, 22)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(451, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(63, 63, 63)
                    .addComponent(newWMSradiobtn)
                    .addGap(18, 18, 18)
                    .addComponent(checkbxpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                    .addGap(18, 18, 18)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(79, 79, 79))
            );
    
            pack();
        }// </editor-fold>                        
    
        /**
         * @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(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(radiobtn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(radiobtn.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 radiobtn().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private org.jdesktop.swingx.JXCollapsiblePane checkbxpanel;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JRadioButton newWMSradiobtn;
        // End of variables declaration                   
    }

Similar Threads

  1. can't navigate from child panel to main panel
    By sharmapiyush in forum New To Java
    Replies: 76
    Last Post: 04-09-2014, 10:39 PM
  2. Applet not appearing as I believe it should
    By calco in forum Java Applets
    Replies: 3
    Last Post: 08-09-2012, 06:57 PM
  3. Panel not appearing in JFrame
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 03-29-2011, 08:53 PM
  4. Replies: 3
    Last Post: 07-27-2010, 10:52 AM
  5. jfilechooser not appearing
    By letter5 in forum New To Java
    Replies: 5
    Last Post: 02-15-2009, 05:45 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
  •