为什么在从Netbeans运行的Java应用程序和从Jar运行的Java应用程序中,相同的字体看起来有所不同? [英] Why the same font looks different in Java app run from Netbeans and run from Jar?

查看:104
本文介绍了为什么在从Netbeans运行的Java应用程序和从Jar运行的Java应用程序中,相同的字体看起来有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java Swing应用程序中,我有一些JTextAreas,我意识到从Netbeans运行时和从Jar文件运行时,文本看起来都不同,为什么?如何使它们看起来相同?

In my Java Swing app I have some JTextAreas, I realize the text looks different when it's run from Netbeans and when the app is run from a Jar file, why ? How to make them look the same ?

JTextArea Client_Side_TextArea=new JTextArea(),Network_TextArea=new JTextArea();

setLayout(new BorderLayout());

Client_Side_TextArea.setFont(new Font("Monospaced",0,15));
Client_Side_TextArea.setForeground(new Color(0,28,218));
Client_Side_TextArea.setPreferredSize(new Dimension(290,300));
Client_Side_TextArea.append("           Client Side\n================================\n");
add("West",Client_Side_TextArea);

Network_TextArea.setFont(new Font("Monospaced",0,15));
Network_TextArea.setBackground(new Color(226,226,226));
Network_TextArea.setForeground(new Color(0,28,218));
Network_TextArea.setPreferredSize(new Dimension(270,300));
Network_TextArea.append("            Network Connection\n =========================================\n");
add("Center",Network_TextArea);

在下图中,上半部分是使用Netbeans运行的应用程序,下半部分是从Jar文件运行时的外观:

In the following image, the upper part is from the app run with Netbeans, the lower part is how it looks when run from a Jar file :

推荐答案

这是预期的行为:如外观& feel 可能会进一步针对特定目的改进字体的选择.除非平台,版本和设置相同,否则字体可能会有所不同.可以在此处找到完整的示例以及有关映射的更多信息.

This is the expected behavior: as discussed in the Font API, each supported platform may map a different physical font to a particulate logical font such as Font.MONOSPACED. Each look & feel may further refine the choice of font for a particular purpose. Unless the platforms, versions and settings are identical, the fonts may vary. A complete example and more on the mapping may be found here.

此外,出于此处所引用的原因,请勿使用setPreferredSize().如果您选择覆盖getPreferredSize(),请确保不属于此陷阱.

In addition, for the reasons cited here, don't use setPreferredSize(). If you choose to override getPreferredSize(), be certain not to fall into this trap.

这篇关于为什么在从Netbeans运行的Java应用程序和从Jar运行的Java应用程序中,相同的字体看起来有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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