Java 代码无法在 Mac OS X 上运行

发布于 2024-12-20 21:06:14 字数 831 浏览 2 评论 0原文

我制作了一个摆动应用程序,我需要根据需要塑造窗户的形状。

因此,为了这个目的,我制作了一个相当于我想要的形状的多边形,然后调用 setShape(myPloygon) 方法,通过该方法以自定义形状创建框架。

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

如果使用 JDK 6 那么

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

它在 Windows 上运行完美,但是当我在 Mac 上尝试它时,窗口形状函数不会创建任何形状,它只显示完整的窗口

那么我该怎么办?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-12-27 21:06:14

恕我直言,您应该得到一个例外,将其粘贴到此处会很有用。当我运行代码时,出现以下异常:

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)

谷歌对该异常的一些研究为您提供了答案,即 OSX 不支持此方法。由于 JDK7 目前不适用于 OSX,因此我们无法确定它是否可以与 JDK7 一起使用。因此,目前 OSX 上没有开箱即用的解决方案 - 除非您自己扩展框架。

更新:

为了完成答案:在 OSX 上的 JDK7 中,截至 2012 年 10 月仍然不支持它

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

喜你已久 2024-12-27 21:06:14

Mac 上的 Java 7 仍然不支持它。

It is still not supported with Java 7 on Mac.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文