[英]sun.font.FontDesignMetrics compile error in JDK 7
Following code compiles well with JDK5 but for JDK7 it throws a compile error saying下面的代码在 JDK5 上编译得很好,但是对于 JDK7,它会抛出一个编译错误说
"sun.font.FontDesignMetrics" is private “sun.font.FontDesignMetrics”是私有的
FontUIResource fontUiResource = (FontUIResource) MyUI.get("MainTitle");
if (fontUiResource != null) {
FontDesignMetrics fontMetrics = new FontDesignMetrics(fontUiResource);
I'm using Intellij 12, just in case if this is information related to the problem.我正在使用 Intellij 12,以防万一这是与问题相关的信息。
It seems the constructors were made private in jdk6.似乎构造函数在 jdk6 中是私有的。 The JavaDoc of the constructor says : "Its private to enable caching - call getMetrics() instead".构造函数的 JavaDoc 说:“启用缓存是私有的 - 改为调用 getMetrics()”。 Such a change is of course always one of the risks when using a private unsupported API.在使用不受支持的私有 API 时,这种更改当然始终是风险之一。
Graphics graphics = image.getGraphics();
FontMetrics metrics = graphics.getFontMetrics(font);
Try this one.试试这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.