Search code examples
javaswingjlayeredpane

Component overlapping in JLayeredPane


I have added two components in JLayeredPane.
1. JWebBrowser
2. JPanel

I added JWebBrowser and JPanel in different layers. JWebBrowser is in 0 i.e bottom layer and JPanel is in 1st Layer.

m_LayeredPane.setLayer(m_WebBrowser, JLayeredPane.DEFAULT_LAYER);
m_LayeredPane.add(m_WebBrowser);
m_LayeredPane.setLayer(m_WebCamPane, JLayeredPane.PALETTE_LAYER);
m_LayeredPane.add(m_WebCamPane);

Now the problem is that JWebBrowser layer is overlapping JPanel layer.

I tried various things like moveToFront() method, defining position at run time, putting both component in same layer and using componentZorder etc.. but still the problem is same.

I am not sure what causing JPanel layer to go back of JWebBrowser layer.


Solution

  • I will bet that even though JWebBrowser derives eventually from JPanel that it behaves as a heavy-weight component with some native components. If so, there are limitations in what you can do, and you may want to read more about mixing heavy and light weight components together in a Swing app: Mixing Heavy and Light Weight Components