4 Replies Latest reply: Jul 12, 2011 9:58 AM by 874712 RSS

    Problem with callin components in jpanel

    874712
      I created a function to change panels in jPanel1 of my application. This code worked for a while, but as I added a panel it stopped working. Now it is not working for any of the panels, it was working with before.
      The change panel function is as follows:
      public void changePanel(JPanel panelchange)
          {
          System.out.println("entered in changePanel function phase1"); // just for debugging purpose
          //panelchange  = new EditMemberPanel();
          panelchange.setVisible(true);
              jPanel1.removeAll();
              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(this.jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(panelchange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              System.out.println("entered in changePanel function phase2"); // just for debugging purpose
              jPanel1Layout.setVerticalGroup(
                  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                      .addComponent(panelchange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap())
      
              );
              System.out.println("exiting changePanel function"); // just for debugging purpose
              
      }
      when I call this fuction all the debugging phrases are coming in the command line, even the size of the panel is changing as the size of the panel passed, but the components are'nt visible. Any help will be highly appreciated. thnx

      Edited by: 871709 on 12-Jul-2011 02:21
        • 1. Re: Problem with callin components in jpanel
          StanislavL
          Just call in the end of the method.
          JPanel1.revalidate();
          JPanel1.repaint();
          • 2. Re: Problem with callin components in jpanel
            874712
            already tried
            jPanel1.revalidate()
            jPanel1.repaint()

            The main problem is that the code was working perfectly fine until I used this function to change a panel. After that the code didnt worked at all.
            not even on the panels it was working on before.
            • 3. Re: Problem with callin components in jpanel
              StanislavL
              I see nothing wrong in the code. Post SSCCE to show the problem.
              Why do you change visibility of the panel? May be somewhere outside it is made invisible.
              • 4. Re: Problem with callin components in jpanel
                874712
                I used netbeans to generate code for me. It had some error, because when I generated this code again it started working.

                Current code is
                public void changePanel(JPanel panelchange)
                    {
                    System.out.println("entered in changePanel function phase1");
                    //panelchange  = new EditMemberPanel();
                    
                        jPanel1.removeAll();
                         jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                
                        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
                        jPanel1.setLayout(jPanel1Layout);
                        jPanel1Layout.setHorizontalGroup(
                            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(panelchange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(162, Short.MAX_VALUE))
                        );
                        jPanel1Layout.setVerticalGroup(
                            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(44, 44, 44)
                                .addComponent(panelchange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(605, Short.MAX_VALUE))
                        );
                
                         panelchange.setVisible(true);
                        System.out.println("exiting changePanel function");
                        jPanel1.revalidate();
                        jPanel1.repaint();
                }