简体   繁体   English

在 JFrame 的内容上显示具有透明背景的图像

[英]Display an image with transparent background over the content of the JFrame

I have a window that looks like this: https://ibb.co/XZ6q43F我有一个看起来像这样的窗口: https : //ibb.co/XZ6q43F

And I want to display a .png image above the current content.我想在当前内容上方显示一个 .png 图像。 The final display should be like this (done with Paint): https://ibb.co/BzQH7V8最终的显示应该是这样的(用 Paint 完成): https : //ibb.co/BzQH7V8

I tried this:我试过这个:

ImageIcon icone = new ImageIcon("images/redcross.png");
JLabel image = new JLabel(icone);
frame.add(image);

But this has no effect.但这没有效果。 Someone can help me ?有人可以帮助我吗? thank you in advance先感谢您

I want to display a .png image above the current content.我想在当前内容上方显示一个 .png 图像。

Use a Glass Pane .使用Glass Pane A glass pane is painted over top of the entire frame.玻璃板涂在整个框架的顶部。 So you can add your image to the glass pane and then make the glass pane visible.因此,您可以将图像添加到玻璃窗格中,然后使玻璃窗格可见。

See the section from the Swing tutorial on How to Use Root Panes .请参阅 Swing 教程中有关如何使用根窗格的部分 The example just paints a dot so you should be able to modify it to draw your image.该示例仅绘制一个点,因此您应该能够对其进行修改以绘制图像。

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

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