Hi,

I have a png image wihtout background and want this png to be my JFrame where the transparent section must be transparent; I have tried different ways I used the setOpaque(), setOpacity(), ImageIO but no clue.

I want only my transparent png as JFrame. Any idea and solution will be appreciated.

It works just fine in Java 7, but there are a number of calls that are needed. Something like this code from an old project's splash screen (maybe some redundancy - it start life under the temporary transparency support in Java 6.21)...

frame.setUndecorated(true); // gets rid of borders title bar etc (call before JFrame is visible)
frame.setBackground(new Color(0, 0, 0, 0)); // frame is transparent    
frame.getRootPane().setOpaque(false); // frame content (rootpane) is transparent...
frame.setOpacity(0.0f); // or maybe this achieves the same thing

JLabel iconLabel = new JLabel(); // use JLabel ImageIcon to paint image
URL imgURL = getClass().getResource("/images/xxx.png"); // transparent png
iconLabel.setIcon(new ImageIcon(imgURL))
frame.add(iconLabel;

Thank you, it worked :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.