How to make JFrame transparent? I want to make my JFrame transparent. User should see the background when my JFrame is on top of it.
I found another solution.
Set the background color of your frame to
// Set the frame background color to a transparent color
yourFrameHere.setBackground(new Color(0, 0, 0, 0));
And remember to set the opacity off of the contentpane (your JPanel or other component)
// turn off opacity of the content pane
yourContentPaneHere.setOpaque(false);
If you do not have any objection in using restricted API classes then you can do this with AWTUtilities
class and setWindowOpacity()
method of that class. Here and here is a tutorial on how to use it? And here is the version using Java native access.
code example
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
javax.swing.JFrame fr = new NewJFrame();
com.sun.awt.AWTUtilities.setWindowOpacity(fr, 0.7 f);
fr.setVisible(true);
}
});
}
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.