背景图像JFrame与内容 [英] Background image JFrame with content
问题描述
我有 JFrame
, BorderLayout
,所有方面都有面板(北,东,...... )。在面板中主要有标签和按钮。
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?
推荐答案
-
put
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
涵盖所有可用的 Rectangle
for JFrame
,然后背景图片
(来自我的第1个永远不会被显示出来,因为这些 JComponents
是on_top JFrame
并且可以隐藏此图片
,
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
(来自我的第1点),然后用 JPanel #setOpaque(false);
,然后这个<另外 JPanel(s)
code> 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与内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!