Java 代码无法在 Mac OS X 上运行
我制作了一个摆动应用程序,我需要根据需要塑造窗户的形状。
因此,为了这个目的,我制作了一个相当于我想要的形状的多边形,然后调用 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 callsetShape(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恕我直言,您应该得到一个例外,将其粘贴到此处会很有用。当我运行代码时,出现以下异常:
谷歌对该异常的一些研究为您提供了答案,即 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:
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 上的 Java 7 仍然不支持它。
It is still not supported with Java 7 on Mac.