简体   繁体   中英

Display an image with transparent background over the content of the JFrame

I have a window that looks like this: https://ibb.co/XZ6q43F

And I want to display a .png image above the current content. The final display should be like this (done with 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.

Use a 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 . The example just paints a dot so you should be able to modify it to draw your image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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