Background image JFrame with content(带有内容的背景图像 JFrame)
问题描述
我有一个带有 BorderLayout
的 JFrame
,四面都有面板(北、东……).面板中主要有标签和按钮.
I have a JFrame
with BorderLayout
, there are panels on all sides (North, East ,...). In the panels there are labels and buttons mostly.
现在我希望框架具有背景图像,一些研究告诉我,我必须更改框架的内容窗格.
Now I want the frame to have a background image, some research told me that i had to change the content pane of my frame.
但是,当我尝试这样做时,内容会被置于后台并且不可见.另外,如果调整框架大小,我不知道如何调整图像大小.
When I try this however, the content gets put in the background and isn't visible. Also, I don't know how to resize the image if the frame is resized.
是否有一个简单的解决方法,或者我是否需要重新编写大部分代码?
Is there an easy fix for this or will I have to rework most of my code?
推荐答案
把带有背景图片的
JPanel
(或JComponent
)放到BorderLayout.CENTER
,然后这个JPanel
填充整个JFrame
区域,其余的JComponents
放到这个JPanel
put
JPanel
(orJComponent
) with background Image to theBorderLayout.CENTER
, then thisJPanel
fills wholeJFrame
area, rest of youtJComponents
put to thisJPanel
四面八方(北、东……)都有 Jpanel.在Jpanels中主要有Jlabels和Jbuttons.
这些 JComponents
涵盖了 JFrame
的所有可用 Rectangle
,然后 Background Image
(从我的第一点开始)永远不会将被显示,因为这些 JComponents
是 on_top JFrame
并且也可以隐藏这个 Image
,
these JComponents
covered all available Rectangle
for JFrame
, then Background Image
(from my 1st point) never will be dispalyed, because these JComponents
are on_top JFrame
and could be hide this Image
as well,
添加 JPanel 和背景图像
(从我的第一点开始),然后用 JPanel#setOpaque(false) 放另一个
,那么这个JPanel(s)
;JPanel
会是透明的,注意JPanel
已经默认实现了FlowLayout
add JPanel with Background Image
(from my 1st point), then put there another JPanel(s)
with JPanel#setOpaque(false);
, then this JPanel
will be transparent, notice JPanel
has implemented by default FlowLayout
这篇关于带有内容的背景图像 JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有内容的背景图像 JFrame


- 如何指定 CORS 的响应标头? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 转换 ldap 日期 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01