I have JPanel has already added to JFrame. And I have dynamically added JPanel. After adding JPanel on the fly it stay near the JPanel added before. How can I delete previous JPanel?
PS
I also think about using cardlayout – is it a good way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a method
getComponents()which will give you the child component inJFrameyou will use it like this way:
Note: this fix only works when you have single
JPanelinsideJFrameat a time, otherwise you gonna remove all yourJPanelsfromJFrame.