简体   繁体   English

JDK 7 中的 sun.font.FontDesignMetrics 编译错误

[英]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.

相关问题 安装Sun JDK 7时的事务检查错误 - Transaction check error when installing Sun JDK 7 Sun JDK 1.5无法解除对泛型的错误 - Sun JDK 1.5 cannot dereference error with generics 如果我使用IBM JDK编译并使用Sun JRE运行,是否存在任何问题 - Are there any issues if I compile with IBM JDK and run with Sun JRE 为什么隐藏的静态方法在Sun JDK 6下编译但在OpenJDK 6和7下导致编译失败? - Why does a hidden static method compile under Sun JDK 6 but cause a compile failure under OpenJDK 6 and 7? Sun JDK /在 Cygwin 上打开 JDK - Sun JDK /Open JDK on Cygwin jdk7:sun.font.fontManager 替换/如何从 fontname 获取文件名信息 - jdk7: sun.font.fontManager replacement/how to get filename information from fontname 我如何在jdk9中获得sun.font的所有类 - How do i get all the classes of sun.font in jdk9 为什么列表的通用演员表 <? extends Set..> 列表 <Set..> 在Sun JDK 6上取得成功但在Oracle JDK 7上无法编译? - Why does a generic cast of a List<? extends Set..> to List<Set..> succeed on Sun JDK 6 but fail to compile on Oracle JDK 7? Sun JDK触发完整的gc - Sun JDK trigger full gc Java在Ubuntu上使用openjdk进行编译,然后在Windows上使用sun java给出错误 - Java compile on Ubuntu with openjdk, then run on windows with sun java gives error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM