简体   繁体   English

如何将图像作为背景添加到JFrame并仍然向其添加其他组件?

[英]How to add image to JFrame as background and still add other components to it?

i want to add an Image as a background to a JFrame but not like 我想将图像作为背景添加到JFrame,但不喜欢

    this.setContentPane(new JLabel(new IamgeIcon("path of image file"));

When i use the above code line i can not see my other components added to the same JFrame. 当我使用上面的代码行时,我看不到其他组件添加到同一JFrame中。 I want to set an image as a background as we see in the html pages where body has a background image and we see other components like buttons and textboxes over it. 我想将图像设置为背景,就像我们在html页面中看到的那样,其中body具有背景图像,并且我们在其上看到其他组件,例如按钮和文本框。 Can anyone please show me how to do that? 谁能告诉我该怎么做? And I want to attach 2 more panels to same JFrame.Please attach the image of your code output. 我想在同一JFrame上再附加2个面板。请附加代码输出的图像。

You can use JLayeredPane 您可以使用JLayeredPane

JLayeredPane adds depth to a JFC/Swing container, allowing components to overlap each other when needed. JLayeredPane为JFC / Swing容器增加了深度,允许组件在需要时彼此重叠。

link how to use Layered Panes 链接如何使用分层窗格

and check this example 并检查这个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM