java - AWT custom window shape using transparent image -
i trying make ui using awt. want use images , transparent components. right cant understand how make main window supposed png image custom shape. areas transparent in image replaced black color. here code use:
public class test { static image image; /** * @param args command line arguments */ public static void main(string[] args) throws ioexception { //switch right thread image = imageio.read(test.class.getclassloader().getresource("resources/images/panel.png").openstream()); swingutilities.invokelater(new runnable() { @override public void run() { frame frame = new frame("test"); frame.setundecorated(true); frame.setbackground(new color(0,0,0,0)); frame.add(new background(image,image.getwidth(frame),image.getheight(frame))); frame.pack(); frame.setsize(image.getwidth(frame), image.getheight(frame)); frame.setvisible(true); frame.setlocationrelativeto(null); } } ); } private static class background extends component { private image img; private int wid, hgt; public background(image img, int wid, int hgt){ this.img=img; this.wid=wid; this.hgt=hgt; } @override public void paint(graphics graphics) { graphics.drawimage(image,0,0,wid,hgt,0,0,wid,hgt,null); } } }
awt components don't have concept of transparency, opaque
try taking @ ...
- how can smooth jframe shape
- jframe same shape image / program running in background
- java swing: transparent png permanently captures original background
- how create translucent , shaped windows
for more examples of using swing
Comments
Post a Comment