在 Java 中的 GridLayout 上覆盖图像
是否可以将一组图像作为网格布局的“背景图像”,而其他图像作为网格布局的“内容”?
如果没有,最好的方法是什么?
Is it possible to have one set of images be the "background image" of a gridlayout and other images be the "content" of the gridlayout?
If not, what's the best way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这当然有可能。将其中之一作为保存 GridLayout 的 JPanel 的背景。这可以通过在 JPanel 的 PaintComponent 方法中绘制图像来完成。如果您希望网格的单元格显示背景图像,请务必将其不透明属性设置为 false。如果它们是 JLabels,则默认情况下已完成此操作。
编辑:例如:
Yes it's certainly possible. Make one the background of the JPanel that holds the GridLayout. This can be done by drawing the image in the JPanel's paintComponent method. If you want the cells of the grid to show the background image though, be sure to set their opaque property false. If they're JLabels this is already done by default though.
Edit: For example:
是的,
drawImage()
可以缩放到容器的完整大小,如图此处。是的,
getSubimage()
在这种情况下很有帮助,如图所示 这里。Yes,
drawImage()
can scale to the full size of the container, as shown here.Yes,
getSubimage()
is helpful in this context, as shown here.