Removing A JPanels Components As Well As Itself?

i know that u can use removeAll() to remove all components from a JPanel, but how can i remove all components from a JPanel AS WELL as remove the JPanel itself?
[174 byte] By [Alex1989a] at [2007-11-27 1:55:21]
# 1
Whats wrong with using the remove(...) method?
camickra at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 2
i tried this.remove(this) but nothing happens when i try to delete the jpanel, and if i try this.removeAll() then all the components in the jpanel are deleted but u can still see a small little box because the jpanel itself hasnt been deleted
Alex1989a at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 3
When you remove components from a panel you use:panel.removeAll();So, when you want to remove the actual panel you would need to do something like:panel.getParent().remove( panel );
camickra at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 4

cool, thnx man that works but just 1 more thing. the jpanel only get deleted like 10 seconds after i click on the delete button.

if(delete == JOptionPane.YES_OPTION){

this.getParent().remove(this);

this.validate();

}

is there a way to make it get deleted almost instantly after the user clicks on the delete button?

Alex1989a at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 5

It gets removed as soon as the code is executed unless you have some other code that is blocking the GUI from repainting itself.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 6

im using multiple classes so itll be kinda difficult to make a SSCCE. but this is the method that deals with deleting the jpanel:

public void buildExitDialog(){

exit = JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to exit?", "Exit", JOptionPane.YES_NO_OPTION);

if(exit == JOptionPane.YES_OPTION){

System.exit(0);

}

}

Alex1989a at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 7

> so itll be kinda difficult to make a SSCCE.

Then is will impossible to offer further help since the information provided give no indication of what your code is like. The code you posted doesn't even show the remove code so I have no idea what you are doing. Why do you even care about removing the panel if you are simply going to exit the GUI.

The GUI won't repaint itself until you answer the question and the modal dialog is closed.

camickra at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 8

a d amn sorry oke wrong method ^^

public void buildDeleteDialog(){

delete = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete this contact?", "Delete", JOptionPane.YES_NO_OPTION);

if(delete == JOptionPane.YES_OPTION){

getParent().remove(this);

validate();

}

}

Alex1989a at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 9
See reply 5. I'm not wasting any more time.
camickra at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...
# 10
ah i think ive got it. when i delete the jpanel its not possible to use the validate() method because the jpanel has already been deleted (nothing to validate). so i need to use validate() on the container that was holding the jpanel.Message was edited by: Alex1989
Alex1989a at 2007-7-12 1:28:13 > top of Java-index,Desktop,Core GUI APIs...