- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
ttf:
otf:
两者是相同的字体,但字体文件类型不同
我在 Windows 7 中运行 Java 7
根据 Adobe 的 Miguel Sousa 的说法,错误不在字体中 https://github.com/adobe/source-sans-pro/issues/32#issuecomment-23319673
我只是将默认字体设置为新字体。 TTF 版本没有任何问题
Font font_o = Font.createFont(Font.TRUETYPE_FONT, fonts.class.getResourceAsStream("fonts/TTF/SourceSansPro-Regular.ttf"));
//Font font_o = Font.createFont(Font.TRUETYPE_FONT, fonts.class.getResourceAsStream("fonts/OTF/SourceSansPro-Regular.otf"));
Font font_n=font_o.deriveFont(Font.PLAIN, UIManager.getLookAndFeelDefaults().getFont("defaultFont").getSize());
UIManager.getLookAndFeelDefaults().put("defaultFont",font_n);
为什么行高不一样?
最佳答案
结论(forums.oracle.com/thread/2573652 与他在那里的帖子一样多,没什么特别的)
. window 。
.金属 。
.雨云。
.经典的 。
Java6 上的 WinXp
.相对 。
此代码将帮助您找到两种字体之间的差异(并将所有差异报告给作者)
从 (java.awt.font.)TextAttribute 返回具体字体的所有可用属性
您可以从(几乎)所有 TextAttributes 中获取详细属性
有输出
java.awt.font.TextAttribute(family)
java.awt.font.TextAttribute(weight)
java.awt.font.TextAttribute(width)
java.awt.font.TextAttribute(posture)
java.awt.font.TextAttribute(size)
java.awt.font.TextAttribute(transform)
java.awt.font.TextAttribute(superscript)
java.awt.font.TextAttribute(char_replacement)
java.awt.font.TextAttribute(foreground)
java.awt.font.TextAttribute(background)
java.awt.font.TextAttribute(underline)
java.awt.font.TextAttribute(strikethrough)
java.awt.font.TextAttribute(run_direction)
java.awt.font.TextAttribute(bidi_embedding)
java.awt.font.TextAttribute(justification)
java.awt.font.TextAttribute(input method highlight)
java.awt.font.TextAttribute(input method underline)
java.awt.font.TextAttribute(swap_colors)
java.awt.font.TextAttribute(numeric_shaping)
java.awt.font.TextAttribute(kerning)
java.awt.font.TextAttribute(ligatures)
java.awt.font.TextAttribute(tracking)
来自代码 Nimbus L&F
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
public class SystemFontDisplayer {
private static final long serialVersionUID = 1L;
private JFrame frame = new JFrame("Nimbus UIDeafaults and Font");
private JComboBox fontsBox;
private javax.swing.Timer timer = null;
private JButton testButton = new JButton("testButton");
private JTextField testTextField = new JTextField("testTextField", JLabel.CENTER);
private JLabel testLabel = new JLabel("testLabel");
private Font font1, font2;
private JMenuBar menuBar1 = new JMenuBar();
private JMenu menu1= new JMenu("Menu 1");
private JMenu menu2= new JMenu("Menu 2");
private JMenuItem menuItem1= new JMenuItem("MenuItem 1");
private JMenuItem menuItem2= new JMenuItem("MenuItem 2");
public SystemFontDisplayer() {
try {
font1 = Font.createFont(Font.TRUETYPE_FONT, SystemFontDisplayer.class.getResourceAsStream("/Images/SourceSansPro-Regular.ttf"));
font2 = Font.createFont(Font.TRUETYPE_FONT, SystemFontDisplayer.class.getResourceAsStream("/Images/SourceSansPro-Regular.otf"));
} catch (FontFormatException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
//ge.registerFont(font1);
ge.registerFont(font2);
String[] fontFamilyNames = ge.getAvailableFontFamilyNames(Locale.getDefault());
fontsBox = new JComboBox(fontFamilyNames);
fontsBox.setSelectedItem(0);
fontsBox.setRenderer(new ComboRenderer());
fontsBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final String fontName = fontsBox.getSelectedItem().toString();
fontsBox.setFont(new Font(fontName, Font.PLAIN, 16));
start();
}
}
});
fontsBox.setSelectedItem(0);
fontsBox.getEditor().selectAll();
menu1.add(menuItem1);
menuBar1.add(menu1);
menu2.add(menuItem2);
menuBar1.add(menu2);
frame.setJMenuBar(menuBar1);
frame.setLayout(new GridLayout(4, 0, 5, 5));
frame.add(fontsBox);
frame.add(testButton);
frame.add(testTextField);
frame.add(testLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(200, 105);
frame.pack();
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fontsBox.setPopupVisible(true);
fontsBox.setPopupVisible(false);
}
});
frame.setVisible(true);
}
private void start() {
timer = new javax.swing.Timer(250, updateCol());
timer.setRepeats(false);
timer.start();
}
public Action updateCol() {
return new AbstractAction("text load action") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
final Font fnt = new Font(fontsBox.getSelectedItem().toString(), Font.PLAIN, 16);
try {
LookAndFeel lnf = UIManager.getLookAndFeel().getClass().newInstance();
final FontUIResource res = new FontUIResource(fnt);
UIDefaults uiDefaults = lnf.getDefaults();
uiDefaults.put("defaultFont", res);
UIManager.getLookAndFeel().uninitialize();
UIManager.setLookAndFeel(lnf);
} catch (InstantiationException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
}
UIDefaults defaults = UIManager.getDefaults();
final FontUIResource res = new FontUIResource(fnt);
Object[] obj = res.getAvailableAttributes();
for (Object objs : obj) {
System.out.println(objs); //returns java.awt.font.TextAttribute
}
defaults.put("defaultFont", res);
SwingUtilities.updateComponentTreeUI(frame);
frame.pack();
}
};
}
public static void main(String arg[]) {
try {
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
SystemFontDisplayer systemFontDisplayer = new SystemFontDisplayer();
}
});
}
private class ComboRenderer extends BasicComboBoxRenderer {
private static final long serialVersionUID = 1L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final Object fntObj = value;
final String fontFamilyName = (String) fntObj;
setFont(new Font(fontFamilyName, Font.PLAIN, 16));
return this;
}
}
}
来自代码 Oldies L&Fs
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
public class SystemFontDisplayer extends JFrame {
private static final long serialVersionUID = 1L;
private JFrame frame = new JFrame("Nimbus UIDeafaults and Font");
private JComboBox fontsBox;
private javax.swing.Timer timer = null;
private JButton testButton = new JButton("testButton");
private JTextField testTextField = new JTextField("testTextField");
private JLabel testLabel = new JLabel("testLabel");
private Font font1, font2;
private JMenuBar menuBar1 = new JMenuBar();
private JMenu menu1 = new JMenu("Menu 1");
private JMenu menu2 = new JMenu("Menu 2");
private JMenuItem menuItem1 = new JMenuItem("MenuItem 1");
private JMenuItem menuItem2 = new JMenuItem("MenuItem 2");
public SystemFontDisplayer() {
try {
font1 = Font.createFont(Font.TRUETYPE_FONT, SystemFontDisplayer.class.getResourceAsStream("/Images/SourceSansPro-Regular.ttf"));
font2 = Font.createFont(Font.TRUETYPE_FONT, SystemFontDisplayer.class.getResourceAsStream("/Images/SourceSansPro-Regular.otf"));
} catch (FontFormatException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex);
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
//ge.registerFont(font1);
ge.registerFont(font2);
String[] fontFamilyNames = ge.getAvailableFontFamilyNames(Locale.getDefault());
fontsBox = new JComboBox(fontFamilyNames);
fontsBox.setSelectedItem(0);
fontsBox.setRenderer(new ComboRenderer());
fontsBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final String fontName = fontsBox.getSelectedItem().toString();
fontsBox.setFont(new Font(fontName, Font.PLAIN, 16));
start();
}
}
});
fontsBox.setSelectedItem(0);
fontsBox.getEditor().selectAll();
menu1.add(menuItem1);
menuBar1.add(menu1);
menu2.add(menuItem2);
menuBar1.add(menu2);
frame.setJMenuBar(menuBar1);
frame.setLayout(new GridLayout(4, 0, 20, 20));
frame.add(fontsBox);
frame.add(testButton);
frame.add(testTextField);
frame.add(testLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(200, 105);
frame.pack();
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fontsBox.setPopupVisible(true);
fontsBox.setPopupVisible(false);
}
});
frame.setVisible(true);
}
private void start() {
timer = new javax.swing.Timer(750, updateCol());
timer.setRepeats(false);
timer.start();
}
public Action updateCol() {
return new AbstractAction("text load action") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
final Font fnt = new Font(fontsBox.getSelectedItem().toString(), Font.PLAIN, 12);
final FontUIResource res = new FontUIResource(fnt);
UIManager.getLookAndFeelDefaults().put("Button.font", res);
UIManager.getLookAndFeelDefaults().put("TextField.font", res);
UIManager.getLookAndFeelDefaults().put("Label.font", res);
SwingUtilities.updateComponentTreeUI(frame);
frame.pack();
}
};
}
public static void main(String arg[]) {
/*try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}*/
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
SystemFontDisplayer systemFontDisplayer = new SystemFontDisplayer();
}
});
}
private class ComboRenderer extends BasicComboBoxRenderer {
private static final long serialVersionUID = 1L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final Object fntObj = value;
final String fontFamilyName = (String) fntObj;
setFont(new Font(fontFamilyName, Font.PLAIN, 16));
return this;
}
}
}
关于java - Source Sans Pro 的 TTF 和 OTF 版本在 Swing (Nimbus L&F) 中的显示方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18461331/
你好, 我有一个 .pro 文件,看起来像: TEMPLATE = subdirs SUBDIRS = foo bar 我想在我的 subdirs .pro 文件中设置一个变量,或定义,或一些可以在
我正在尝试使用 QtCreator 构建一些项目。 这两个 .pro 文件之间有很多共同的代码。 有没有办法让这两个 .pro 文件调用另一个包含共同信息的唯一 .pro 文件? 最佳答案 是的,参见
好的,我正在为我构建的网络购物车使用 PHP/SQL。我也有所需的 Paypal 帐户(企业),所以我有一个 API 身份验证。我还创建了一个沙箱帐户并在那里也获得了 API 身份验证。 我已经通读了
我已经使用 Unity 4 Pro 试用版几个星期了。我决定升级到实际的专业版,这样我就可以发布游戏了。 我遇到的问题是,即使我已经升级了试用版本,(是的,我已经把新的序列号放在了 Unity 给我的
我目前正在开发一款完全用 Java 编写的游戏。截至目前,我的主循环正在 Action Performed 方法中运行,该方法由计时器每 100 秒更新一次。在这个循环中,代码会重新绘制,并对玩家位置
我想与组织内的用户共享 Power BI 报告。我有一个 Power BI Pro 帐户。其他用户没有。这可能吗? 我与之共享的用户无法打开报告。它说他们需要在 Pro 帐户中。 最佳答案 Shari
有没有什么办法可以将Ant Design Pro表格的默认操作文本翻译成英文。我正在使用 Umi 默认组件 最佳答案 Ant Design Pro Table 的操作有默认的翻译。您将需要导入它们并将
我有一个来 self 们供应商的 Java 应用程序。以管理员身份安装应用程序后,我尝试以管理员身份打开应用程序,但没有任何反应。我已经转到程序图标指向的位置,它转到 Javaw.exe 文件: "C
我无法使用 PayPal Payments Pro 选项创建 Paypal 沙盒测试帐户(使用 Pro 表示您自己是商家)。我在创建测试帐户时选择了该选项,但当我查看该帐户的详细信息时,它显示了 Ac
这是代码,请帮助我在第19行中使元组索引超出范围错误 import math n = 7 x = 0.5,1.2,2.1,2.9,3.6,4.5,5.7 y = 3.2,5.2,9.3,14.6,20
有人知道怎么做吗? Using File>加载C头文件失败错误代码太多。 最佳答案 C++ 标准库中有太多 IDA 无法理解的编译器相关宏。由于许多原始数据类型,例如 uint32_t 等,已经被 I
我有一个基于 Java SWING 的桌面应用程序,有人问我它是否可以在 Microsoft Surface Pro 或 Pro 2 上运行。据我所知,这些应用程序使用的是 Windows 8/8.1
我已经在 Android 中创建了一个模块以在我的主应用程序中使用,并且似乎有两个文件Consumer-rules.pro 和 proguard-rules.pro。 我想了解以下内容 所有模块代码都
好的,事情是这样的。我的一个客户声称他在使用 Safari 浏览器的 Macbook Pro 上查看网站时看不到社交图标(在屏幕的左侧)。这些图标在我测试过的所有设备上都清晰可见。是否有任何 Macb
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的
将应用程序提交到应用程序商店进行审核后,我在 iTunes Connect 中收到以下警告。我在 iTunes Connect 中没有看到上传 iPad Pro 屏幕截图的选项。 请告诉我这里可以做什
我在 Visual Studio 2010 中创建了一个愚蠢的小“游戏”来尝试使用 XNA 并自学游戏开发。它所做的只是循环颜色并在一些小球周围弹跳。我有为 .NET 4.0 客户端配置文件构建的项目
使用最新的TensorFlow(2.13)时遇到与GPU相关的错误。请注意TensorFlow-Metals页面上提供的测试模型培训,以验证我的设置工作正常。。请指点一下。。以下是我使用的命令-该脚本
我正在学习Pro*c语言。我正在尝试创建一个序列。但是当我们创建游标时我没有得到要使用哪个关键字,然后我们将其声明为 EXEC SQL DECLARE CUR_NAME CURSOR FOR
为了响应nodejs的大红大紫,最近应用其实现了一些server端的功能。数据库方面选择了老少咸宜的MySQL。今后肯定还会有相关应用需求。特此记录Mac系统下如何安装、配置MySQL及其管理工具S
我是一名优秀的程序员,十分优秀!