>> Is it possible to successfully add it to another JComponent, or must
>> you set it as the contentPane of a JFrame?
[quoted text clipped - 5 lines]
> JApplet, JDialog, or JInternalFrame automatically has a layered
> pane. ..."
Thank you, but that wasn't really what I was trying to get at. None
of the containers described in that quote are JComponents.
I don't want the entire JApplet to use a layered pane. I want a
subsection, added to a JPanel, to be layered.
The tutorial you linked, which I have read (but possibly not in enough
detail), has example code that uses JFrame's setContentPane() method to
use a custom built JLayeredPane. I want to know if I can do something
like:
JPanel panel = new JPanel();
JLayeredPane layers = new JLayeredPane();
// add stuff to JLayeredPane
panel.add(layers);
So far, it hasn't worked: the area that should contain the layers is
just grey/blank.
Here's some example code; the actual app for which I'd like this
functionality is pretty complicated. But I think if I could get this
sample to work, I could also get the app to work:
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
public class LayeredPaneTest
{
public static void main (String[] args)
{
go();
protected static void go()
{
JFrame frame = new JFrame();
JLayeredPane pane = new JLayeredPane();
pane.add(new JLabel("foo"), new Integer(0));
pane.add(new JLabel("bar"), new Integer(1));
frame.getContentPane().add(pane);
frame.pack();
frame.setVisible(true);
}
}
}

Signature
monique
Monique Y. Mudama - 27 Feb 2006 20:05 GMT
> Here's some example code; the actual app for which I'd like this
> functionality is pretty complicated. But I think if I could get
> this sample to work, I could also get the app to work:
I figured it out. I needed setBounds() on the component added to the
JLayeredPane.
Unfortunately, that doesn't seem like it's very helpful when the
components need to stretch ... I guess there's probably a way to set
up a listener to continuously redo the setBounds()? But surely
there's a better way?

Signature
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Vova Reznik - 27 Feb 2006 20:06 GMT
OK, no problem, just follow
> import javax.swing.JFrame;
> import javax.swing.JLabel;
[quoted text clipped - 11 lines]
> JFrame frame = new JFrame();
> JLayeredPane pane = new JLayeredPane();
Component c = new JLabel("foo");
/*
* IMPORTANT size of your JLabel is 0x0
* :)
* That is why you cannot see it!!!
*/
c.setSize(100, 20);
> //pane.add(new JLabel("foo"), new Integer(0));
pane.add(c, new Integer(0));
> pane.add(new JLabel("bar"), new Integer(1));
>
> frame.getContentPane().add(pane);
/*
* Some components may need setVisible (JInternalFrame for example)
*/
> frame.pack();
> frame.setVisible(true);
> }
>
> }
> }