The proper way to achieve your goal is to using a card layout and switching panels accordingly.
You ca get some idea on how card layout stuff is working in here
Question
I'm quite new to Swing, and I'm programming an application with NetBeans' UI designer. Now I have an JPanel called "editorPanel", and it must be able to display multiple things. (so, sometimes it has to display an image, and sometimes it has to display a text editor)
I have made separate panels for this, so say I'd have a JPanel called ImagePanel and one called TextPanel. It has to switch easily between them, so I tried this:
editorPanel = new ImagePanel();
But that didn't work.
So, what I want to do, is set an empty panel to a defined panel. How can I make this work?
Solution
The proper way to achieve your goal is to using a card layout and switching panels accordingly.
You ca get some idea on how card layout stuff is working in here