Java - 是否可以将 JLayeredPane 放入 JScrollPane 中?
当我尝试将 JLayeredPane 放入 JScrollPane 中时,我得到一个空白窗口(带有白色背景),而不是我尝试渲染的内容(它可能是图像、按钮、画布)。有谁知道布局管理器可能导致它的问题吗?是否可以?
编辑: 感谢 camickr 的帮助,我现在可以将 JLayeredPane 放入 JScrollPane 中,尽管现在我面临着一个不同的问题:
我正在使用一个非常大的图像,并且我试图将其放入 JScrollPane 中的 JLayeredPane 中。由于某种原因,当我使用这个大图像时(我没有收到堆溢出异常),我得到这个空白(白屏)。有人经历过这样的事情吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这几乎是一个猜测,因为您没有提供太多信息,但对我来说,JLayeredPane 的首选大小是 (0,0),而您看到的“白色”是 JScrollPane 的 JViewport 子项的背景。首先尝试在 JLayeredPane 上设置首选大小。
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.
阅读关于如何使用分层窗格的 Swing 教程工作示例。
更改以下行:
Read the Swing tutorial on How to Use Layered Panes for a working example.
Change the following line: