简体   繁体   中英

Java code does not work on Mac OS X

I made a swing application, where I have need to shape the windows as I want.

So for this purpose, I made a polygon which is equivalent to my desire shape, and then call setShape(myPloygon) method, by which a frame is create in custom shape.

final Window w = new TestFrame();
w.setVisible(true);
Polygon polygon=new Polygon();
polygon.addPoint(10,0);
polygon.addPoint(0,10);
polygon.addPoint(0,573);
polygon.addPoint(10,583);
polygon.addPoint(570,583);
polygon.addPoint(580,573);
polygon.addPoint(580,545);
polygon.addPoint(720,545);
polygon.addPoint(730,535);
polygon.addPoint(730,90);
polygon.addPoint(720,80);
polygon.addPoint(580,80);
polygon.addPoint(580,10);
polygon.addPoint(570,0);
w.setShape(polygon);     //method in jdk7

If use JDK 6 then

com.sun.awt.AWTUtilities.setWindowShape(w, polygon);

It runs perfect on windows, but while I try it on Mac then window shape function do not create any shape, it shows the full window only

So what should I do?

IMHO you should get an exception, and it would have been usefull to paste this here. When I run the code, I get the following exception:

Exception in thread "main" java.lang.UnsupportedOperationException: The PERPIXEL_TRANSPARENT translucency kind is not supported
at com.sun.awt.AWTUtilities.setWindowShape(AWTUtilities.java:258)
at de.project.test.WindowShape.main(WindowShape.java:31)

Some research in google for that exception gives you the answer, that this method isn't supported on OSX. And since the JDK7 isn't here for OSX at the moment, we can not say if it will work with JDK7. So there is no solution out of the box at the moment on OSX - excepet you extend a frame by yourself.

Update:

To complete the answer: in JDK7 on OSX, it is still not supported up to Oct, 2012

Mac 7上的Java 7仍然不支持此功能。

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