JTextPane的等宽字体/符号 [英] Monospaced font/symbols for JTextPane

查看:121
本文介绍了JTextPane的等宽字体/符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JTextPane构建类似控制台的输出.因此,我使用的是等宽字体:

I want to build a console-like output using JTextPane. Therefore I am using a monospaced font:

textpane.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

这对于所有种类的字母数字(例如az,0-9等)都可以正常工作,但是当涉及到像 \ u2588 这样的符号(█)时,字体就不是等距了.

This works fine for all kind of alphanum (like a-z, 0-9 etc.) characters, but when it comes to symbols like '\u2588' (█), the font isn't monospaced anymore.

我忘记了什么吗?还是没有包含smybols的等宽字体?

Did I forgot something? Or isn't there a monospaced font which includes smybols?

推荐答案

好吧,首先,对我来说,您要在此解决几个不同的问题,因此,我将尝试分别解决这两个问题

Ok, first off, it sounds to me like you're trying to address a couple of different things here, so I'll try to address them both separately.

1.您需要一种用于所有unicode字符,符号或其他符号的等宽字体.

根据此页页面,共有12886个字母数字和符号"字符由Unicode 3.2标准定义. Unicode现在是6.0,所以我们可以假设这个数字现在更大了.我在这里还假设字母数字"表示英文字符,因为Unicode支持超过100000个跨越多种语言的字符.无论如何,12886英文识别的字符和符号仍然很多,我怀疑是否有许多免费字体可以支持所有这些字符.

According to this page, there were 12886 alphanumeric and "symbol" characters defined by the Unicode 3.2 standard. Unicode is now at 6.0, so we can probably assume that number is larger now. I'm also assuming here that "alphanumeric" means English characters, because Unicode supports over 100000 characters spanning many languages. At any rate, 12886 English-recognized characters and symbols is still A LOT, and I doubt that there are many free fonts that support all of them.

也就是说,我最终对大多数需要带有字符支持的等宽字体的Java应用程序使用Courier New.它支持您上面提到的'\ u2588'字符以及许多其他重要的字符,例如学位"符号.

That said, I end up using Courier New for most of my Java applications that need a mono-spaced font with character support. It supports the '\u2588' character you mentioned above as well as many other important ones like the "degrees" symbol.

2.此等宽字体需要为跨平台"

我肯定知道Mac OS X和所有Windows风格都支持Courier New,并且我运行的Linux版本也都支持(RedHat ...记不清版本号),尽管不是所有Linux版本拥有本机字体.无论如何...您可以尝试Courier New并查看它是否适合您.如果没有,您可能可以在网上找到免费的工具来测试字体/字符支持.

I know for certain that Mac OS X and all flavors of Windows support Courier New, and the versions of Linux I run on do too (RedHat... can't remember the version number), although not all Linux versions have this font natively. Anyway... you might try Courier New and see if it works for you. If not, you can probably find free tools online for testing font/character support.

最终想法

我不想这么说,但是我怀疑是否有很多字体支持Unicode标准定义的所有字母数字/符号字符,至少所有字体都是等宽,跨平台和自由的.如果可能的话,可能更值得您花时间去弄清楚您肯定需要哪些符号,然后选择一种支持这些符号的字体,然后再由您知道将在其上运行应用程序的平台所支持.不幸的是,如果您绝对需要对所有Unicode符号的支持,它可能会免费提供.

I hate to say it, but I doubt that there are many fonts out there that support all alphanumeric/symbol characters defined by the Unicode standard, least of all being mono-spaced, cross-platform, and free. If possible, it might be more worth your time to try to figure out what symbols you will need for certain, then choose a font that supports those symbols and is in turn supported by the platforms you know you will run your application on. If you absolutely need to have support for all Unicode symbols, unfortunately, it probably won't come free.

这篇关于JTextPane的等宽字体/符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆