Hey everyone,
The
BorderLayout.WEST area of my main JFrame has buttons that trigger certain events.
When an event occurs, the content of the
BorderLayout.CENTER area of the main JFrame should change, i.e. one component is substituted for another using add and remove methods.
This works fine with single items, but now I need to display a mini layout (background, JList, and 2 text-based components) within that content area.
So, I created a new class that extended JPanel and contained a constuctor specifying all the requirements of the display, with the idea that I would keep the code for the new layout separate for clarity and just instantiate an instance of it in my actionPerformed(....) event method.
Buttonclick --> actionPerformed --> make instance of JPanel --> add to BorderLayout.CENTER
I intended to use JLayeredPane to arrange the new display within my JPanel, but have found that I need a JFrames' contentPane to enable the layered pane,
// jlp=JLayeredPane
// jf=JFrame
e.g. jlp = jf.getLayeredPane(); I tried it with the JPanel -
e.g. jlp = this.getLayeredPane(); // this=the current JPanel instance/object
but that doesn't work.
How can I make a separate customised JPanel with layered components, create an instance of it in my main class and drop it into a JFrame layout if my JPanel doesn't have a reference to the main JFrame?
I have tried extending JFrame instead of JPanel in the separate class - that works, but it has a title bar and I don't want that to show. I need it to appear like a panel, that's all.
Any comments?
Regards, J
