Java - Is it possible to put a JLayeredPane inside JScrollPane?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 12:17:26

问题


when I try putting my JLayeredPane inside a JScrollPane I get a blank window (with white background) instead of the content I am trying to render (it could be an image, a button, a canvas). Does anyone know of a problem with layout managers that might cause it? Is it possible?

EDIT: thanks to camickr help, I can now put a JLayeredPane inside a JScrollPane, though now I am facing a different problem:

I am using a very large image and I am trying to put it inside my JLayeredPane that's inside the JScrollPane. From some reason when I use this large image (I am not receiving a heap overflow exception) I get this blank (white screen). Has anyone experienced something like this?


回答1:


Well this is pretty much a guess because you haven't provided much information, but it sounds to me like the JLayeredPane's preferred size is (0,0), and the "white" you're seeing is the background of the JScrollPane's JViewport child. Try setting a preferred size on the JLayeredPane as a start.




回答2:


Read the Swing tutorial on How to Use Layered Panes for a working example.

Change the following line:

// add(layeredPane);
add(new JScrollPane(layeredPane));


来源:https://stackoverflow.com/questions/1456143/java-is-it-possible-to-put-a-jlayeredpane-inside-jscrollpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!