简体   繁体   中英

The method setOpacity(float) from the type Window is not visible

I'm trying to use the method setOpacity but am getting the error

The method setOpacity(float) from the type Window is not visible

Here is my full code

import javax.swing.JDialog;

public class TranslucentWindow {

    public static JDialog frame;

    public static void main(String[] args) {


        frame = new JDialog();
        frame.setUndecorated(true);
        frame.setVisible(true);
        frame.setOpacity(0.15f);
        frame.setLocation(0, 0);
        frame.setSize(100, 100);

    }

}

EDIT: My Java version

java version "1.6.0_27"

OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1~deb7u1)

OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

And Eclipse compiler was on 1.6 but I changed it to 1.7

Window transparency support was added to the public API's in Java 7

Take a look at How to create a translucent and shaped window for more details

This functionality, which is part of the public AWT package in the JDK 7 release, takes three forms, as follows:

If you need to use this functionality in Java 6, update 12 and above introduces the private API AWTUtilities , which provides much of the same functionality.

Check out this for a basic example

Make sure you are using java 7. This won't work otherwise. setOpacity() isn't part of <= java6

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