感谢您抽出时间。我的问题是关于在一个 JTextPane 中显示不同字体的问题。我的客户希望在一个字段中查看两种不同语言的单词。他们明确表示希望不同的语言(即阿姆哈拉语、阿拉伯语、科普特语和希伯来语)以不同的字体显示。这些显然是非标准字体,我不能依赖用户在其操作系统上安装所需的字体。
根据我的研究,我发现我可以在运行时加载字体文件并相应地设置 JTextPane 的字体,如果我只想使用一种字体而不是两种字体,这很好。我还阅读了有关将字体添加到操作系统字体目录或 JRE 字体目录的信息,概述 此处。
然而,我希望能够在不改变用户操作系统的情况下使用这些字体。我运气不好吗?
再次感谢您的宝贵时间,我期待任何有好主意的回复!
Thanks for your time. My question is regarding the display of different fonts within the one JTextPane. My client wishes to view a word in two different languages within the one field. They've explicitly specified that they wish the different languages (namely Amharic, Arabic, Coptic and Hebrew) to be shown with different fonts. These are obviously non-standard fonts and I can't rely on the user having the required fonts installed on their OS.
From my research I've found that I can load a font file at runtime and set the JTextPane's font accordingly, which is fine if I just wanted to use one font, not two. I've also read about adding fonts to the OS' font directory or the JRE's font directory, outlined here.
I was hoping however, that there might be away to use the fonts without altering the user's OS. Am I out of luck?
Thanks again for your time and I look forward to any replies with bright ideas!
发布评论
评论(1)
JTextPane 可以使用多种字体。
查看 Swing 教程中关于文本组件功能的部分,了解在文本窗格中使用文本属性的示例。
编辑:
阅读 createFont() 方法的 API 看起来您应该能够使用:
A JTextPane can use multiple fonts.
Check out the section from the Swing tutorial on Text Component Features for an example of playing with the attributes of the text in the text pane.
Edit:
Reading the API for the createFont() method it looks like you should be able to use: