Java JTextArea默认字体在Windows中非常小
我使用的是platform look and Fall,在Linux上,我的JTextArea非常可读 但在Windows上,它使用“等距9”,文本非常小 为什么,最好的解决方法是什么Java JTextArea默认字体在Windows中非常小,java,swing,look-and-feel,jtextarea,Java,Swing,Look And Feel,Jtextarea,我使用的是platform look and Fall,在Linux上,我的JTextArea非常可读 但在Windows上,它使用“等距9”,文本非常小 为什么,最好的解决方法是什么 为什么默认的Windows look and fell在JTextArea中使用如此小的字体?如果您想要一致的外观,请使用Nimbus或Metal外观,而不是操作系统默认的外观。这也将允许您调整任何设置。另外,我个人认为Nimbus的外观要比其他的平滑得多。您可以使用JTextArea1.setFont(Font
为什么默认的Windows look and fell在JTextArea中使用如此小的字体?如果您想要一致的外观,请使用Nimbus或Metal外观,而不是操作系统默认的外观。这也将允许您调整任何设置。另外,我个人认为Nimbus的外观要比其他的平滑得多。您可以使用
JTextArea1.setFont(Font(String name,int style,int size))
方法指定JTextArea组件的特定字体类型。例如
jtextraea1.setFont(新字体(“Arial黑色”,Font.BOLD,8))代码>
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
public class NewJFrame extends javax.swing.JFrame {
private JTextArea jTextArea1;
private JTextArea jTextArea2;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public NewJFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jTextArea1 = new JTextArea();
getContentPane().add(jTextArea1, BorderLayout.NORTH);
jTextArea1.setText("This is a fox running slow");
jTextArea1.setFont(new Font("Arial Black", Font.BOLD, 8));
jTextArea1.setPreferredSize(new java.awt.Dimension(164, 114));
}
{
jTextArea2 = new JTextArea();
getContentPane().add(jTextArea2, BorderLayout.SOUTH);
jTextArea2.setText("This is a fox running slow");
jTextArea2.setFont(new Font("Book Antiqua", Font.ITALIC, 12));
jTextArea2.setPreferredSize(new java.awt.Dimension(384, 129));
}
pack();
setSize(400, 300);
} catch (Exception e) {
//add your error handling code here
e.printStackTrace();
}
}
}
我刚刚在TextArea中使用了TextField字体
textArea = new JTextArea();
textArea.setFont(UIManager.getFont("TextField.font"));
照办
textArea.setFont(新字体(“Arial”,Font.PLAIN,16))代码>
这会将textarea内的所有文本更改为相同大小的字体。与其创建新字体,不如使用现有字体,因为这样可以按平台外观保存字体集,还可以避免unicode字符的问题:
textArea.setFont(textArea.getFont().deriveFont(12f)); // will only change size to 12pt
下面是一个解决方案,您可以使用它一次更改所有JTextArea,而不是每次添加新文本区域时都使用setFont()
UIManager.getDefaults().put("TextArea.font", UIManager.getFont("TextField.font"));
设置外观后,在应用程序启动时调用此函数
大多数L&F对JTextArea和JTextField使用相同的字体,奇怪的是Windows没有。在Windows上,它看起来与OS Windows非常不同。我真的更喜欢“系统”的外观和感觉,无论在任何平台上,Nimbus和Metal看起来都是异类的,有些用户真的不喜欢它。我希望外观奇特的应用程序的时代已经过去。我不想指定字体,我只想指定字体的大小:)默认字体应该使用djTextArea没有getStyle()方法。setFont方法不接受3个参数。嗯,无法复制:在我的系统(Vista)上,字体为单间距16。通常,WindowLookAndFeel使用操作系统字体设置——那么您的系统设置可能太小了?你的赢版是什么?