---
title: "Open another panel inside another panel after pressing button"  
description: "Open another panel inside another panel after pressing button"  
author: "Anonymous User"  
published: 2015-12-04  
updated: 2015-12-04  
canonical: https://www.mindstick.com/forum/33682/open-another-panel-inside-another-panel-after-pressing-button  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Open another panel inside another panel after pressing button

I have been [getting an error](https://answers.mindstick.com/qa/95244/why-do-you-keep-getting-an-error-message-ox800ccc0b) saying that i didn't [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) some [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best)(the [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) performed) but i [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) did. I'm [having trouble](https://answers.mindstick.com/qa/50524/how-to-fix-iphone-8-that-s-overheating-and-having-trouble-turning-on) opening the panel2.

```
public class panel1 extends JPanel implements ActionListener(){    private panel2 p2=new panel2();    private JButton button;    public panel1(){    button=new JButton("open panel2");    add(button,BorderLayout.BEFORE_FIRST_LINE);    button.addActionListener(new ActionListener(){        @Override        public void actionPerformed(ActionEvent ae) {            add(p2);        }    });  }}
```

## Replies

### Reply by Anonymous User

You can check the below code for replacing jpanel without switching jframe.

```
contentPanel.removeAll();        contentPanel.repaint();        contentPanel.revalidate();        contentPanel.add(//add your panel here);        contentPanel.repaint();        contentPanel.revalidate();
```


---

Original Source: https://www.mindstick.com/forum/33682/open-another-panel-inside-another-panel-after-pressing-button

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
