Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Jpanel refresh problem

843806Nov 12 2008 — edited Nov 13 2008
Hi,

i want to delete a panel when a button is clicked. The problem is, parent panel is not refreshing for some reason. When i resize my application, the panel disappears. I also get some exceptions when i delete the panel:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.JComponent._paintImmediately(JComponent.java:5085)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
I am kind of embarrased because I know that I am obviously doing something wrong while validating parent panel. I tried validate, revalidate, invalidate-validate but none of them worked. Here is the related code segment:
                // delete channel panel
                panels.elementAt(pIndex).remove(channels.elementAt(i).getChannelPanel());
                
                // delete vertical separator if exists
                if(channels.elementAt(i).getSeparator() != null)
                    panels.elementAt(pIndex).remove(channels.elementAt(i).getSeparator());
                
                // validate panel
                panels.elementAt(pIndex).revalidate();
                channels.remove(i);
                
                // delete row panel if it is empty
                if(panels.elementAt(pIndex).getComponentCount() == 0)
                {
                    System.out.println("deleting panel and seperator");
                    
                    // remove row panel & horizontal separator
                    jPanel1.remove(panels.elementAt(pIndex));
                    jPanel1.remove(horSep.elementAt(pIndex));
                    
                    // validate main panel
                    jPanel1.revalidate();
                    
                    horSep.remove(pIndex);
                    panels.remove(pIndex);
                    
                }
If you find the code confusing here is a summary of my layout:

On top there is main panel (jPanel1 - boxlayout), i add row panels to main panel (members of panels vector - flow layout) , i put 4 channel panel to a row panel (channels.getChannelpanel)

i remove channel panels one by one and if row panel is empty i remove it from main panel

thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2008
Added on Nov 12 2008
7 comments
743 views