Be patient I'm still a beginner, no rude comments please.
So the goal of this question is so I learn how to set the background of my already transparent JFrame to be blurred. This is what I have now.
So as you can see it's transparent, but not blurry. I was thinking maybe Java has some process that can blur an image from JAR and use it as a background without changing the original image. So I looked and looked, but nothing I found helped me.
The background of the JFrame, as seen above, is a label with no text but rather the 'background image' as the label's icon.
Organization of JAR :
META-INF(folder) > MANIFEST.MF
SystemInfo(folder) > classes and background image
This is the code I have so far, but its not working.
setOpacity(); // sets opacity of the background
Color c = Color.WHITE; // default color
setColor(c);
//background = (new JLabel((Icon) new ImageIcon(a)));
BufferedImage mshi = null;
try{mshi = ImageIO.read(new File("SystemInfo/black.png"));}catch(Exception e){e.printStackTrace();}
BufferedImage databuf = new BufferedImage(mshi.getWidth(null),
mshi.getHeight(null),
BufferedImage.TYPE_INT_BGR);
Graphics g = databuf.getGraphics();
g.drawImage(mshi, 455, 255, null);
float[] blurKernel = {
1 / 9f, 1 / 9f, 1 / 9f,
1 / 9f, 1 / 9f, 1 / 9f,
1 / 9f, 1 / 9f, 1 / 9f
};
BufferedImageOp blur = new ConvolveOp(new Kernel(3, 3, blurKernel));
mshi = blur.filter(mshi, new BufferedImage(mshi.getWidth(),
mshi.getHeight(), mshi.getType()));
g.dispose();
//background = (new JLabel((Icon) new ImageIcon(mshi)));
background.setIcon((Icon)new JLabel(new ImageIcon(mshi)));
Errors the above code produces :
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at SystemInfo.GuiMain.cinitComponents(GuiMain.java:150)
at SystemInfo.GuiMain.<init>(GuiMain.java:30)
at SystemInfo.GuiMain$8.run(GuiMain.java:256)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at SystemInfo.GuiMain.cinitComponents(GuiMain.java:152)
at SystemInfo.GuiMain.<init>(GuiMain.java:30)
at SystemInfo.GuiMain$8.run(GuiMain.java:256)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
In-case its needed, the setOpacity(); funciton :
float fOpacity = (float)opacity/10;
String sOpacity = Float.toString(fOpacity)+"f";
this.setOpacity(Float.parseFloat(sOpacity));
My main goal is to have the JFrame produce somthing like this :
As you can see, the frame blurs out the computer background slightly and is transparent.
Thank you all in advance.