Suppose I have a JLayeredPane called mainPanel that is using a BorderLayout. I also have a JLabel called backgroundLabel that contains an image. How would I go about adding the backgroundLabel to the bottom layer of mainPanel?
mainPanel.add(backgroundLabel, new Integer(-1), new Integer(0));
The above line seems like the obvious answer, and would work if the mainPanel was using a null layout. The BorderLayout in mainPanel is not liking the command and gives the following stack trace.
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null)
at java.awt.BorderLayout.addLayoutComponent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
How would I go about adding the backgroundLabel to the bottom layer of the mainPanel without conflicting with the BorderLayout?