我正用Swing写一个简单的记事本,在实现设置显示字体时遇到了麻烦
我的系统是WinXP,安装了一些额外的字体,比如“华康简魏碑”。 我在程序中,这样写:
Font myfont = new Font("华康简魏碑",Font.PLAIN, 20);
textArea.setFont(myfont, Font.PLAIN, 20));
(其他代码很简单,就不贴上来了,textArea是JTextArea,用来显示打开的文本文件的) 程序运行至setFont时报错,
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c931ec3, pid=3428, tid=256
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0-b64 mixed mode, sharing)
# Problematic frame:
# C [ntdll.dll+0x11ec3]
#
# An error report file with more information is saved as hs_err_pid3428.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# 搜索了一下,似乎是JVM本身的bug,对于一些非标准的字体经常出现这种情况,但不知有什么办法能识别一个Font对象是否会引起这种异常,也就是说:
Font f = new Font("aName", Font.PLAIN, 20 );
if(f.check() == true)
{
//字体正常,设置字体
}
else
{
//字体不正常,do nothing
}
这个boolean check()应该怎样实现,请教高手,万分谢谢
我的系统是WinXP,安装了一些额外的字体,比如“华康简魏碑”。 我在程序中,这样写:
Font myfont = new Font("华康简魏碑",Font.PLAIN, 20);
textArea.setFont(myfont, Font.PLAIN, 20));
(其他代码很简单,就不贴上来了,textArea是JTextArea,用来显示打开的文本文件的) 程序运行至setFont时报错,
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c931ec3, pid=3428, tid=256
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0-b64 mixed mode, sharing)
# Problematic frame:
# C [ntdll.dll+0x11ec3]
#
# An error report file with more information is saved as hs_err_pid3428.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# 搜索了一下,似乎是JVM本身的bug,对于一些非标准的字体经常出现这种情况,但不知有什么办法能识别一个Font对象是否会引起这种异常,也就是说:
Font f = new Font("aName", Font.PLAIN, 20 );
if(f.check() == true)
{
//字体正常,设置字体
}
else
{
//字体不正常,do nothing
}
这个boolean check()应该怎样实现,请教高手,万分谢谢
解决方案 »
- 关于static的问题
- JAVA连接数据库出现 No suitable driver异常怎么办?请求各位大侠帮忙!!
- 急急!一道程序题, 请各位帮帮忙!!散分!!!!
- applet 图片拖动的问题(再线等)
- java 漏洞? 关于final 和 method anonymous class
- 大家好,有谁知道自己做的javabean在TOMCAT怎么配置吗?比如我的虚拟目录是d:\myjsp,并且已配好,可是就是不知道自己做的bean在server.x
- 怎么提取字符
- 服务器上启动的java单个程序如配置debug端口进行调试,像jboss那样,求大牛!!
- 急求java实现IEC104规约的例子
- 是不是星多的就是高手,星少的就是菜鸟?
- 继续请教关于UDP返回字符处理的方法,请指点下 谢谢
- 分如果不够再开帖子加
只要是文本文件中能够使用的字体都可以使用
不存在的字体不会抛出异常,系统会使用默认字体
关注中。
this.name = (name != null) ? name : "Default";
this.style = (style & ~0x03) == 0 ? style : 0;
this.size = size;
this.pointSize = size;
}如果 name == null 的时候就是 "Default",所以如果系统不存在这个字体是不会抛异常的。
字体存在而抛异常的情况没有遇到过,有待于研究
不过可以这样解决嘛:Font f = new Font("aName", Font.PLAIN, 20 );
try {
// 字体正常,设置字体
} catch(Exception ex) {
// 字体不正常,do nothing
}