The problem is you are setting a layout manager to the JLayeredPane
layeredPane.setLayout(new BorderLayout());
In of it self, this is not a problem, but your choice of layout manager is.
BorderLayout
will only a single componet to occupy any of it's 5 predefined positions. This means when you add your second component, it, effectively, replaces the first.
Try using someone like GridBagLayout
instead. Providing a single GridBagConstaint
set so that the weightx/y
values ara equal to 1
, the fill property is set to BOTH
and it's gridx/y
properties are set to 0
Unlike BorderLayout
, GridBagLayout
will allow you to layout components to the same position