7
Java 6中的本地Windows LookAndFeel似乎錯誤地設置了某些字體的大小。爲什麼Windows LookAndFeel使字體太小?
測試程序:
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Test {
public static void main(String[] arg) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
final JMenuBar mb = new JMenuBar();
final JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
mb.add(file);
final JToolBar toolbar = new JToolBar();
final JButton button = new JButton("Button");
toolbar.add(button);
final JLabel label = new JLabel("Basic Colors");
final JPanel panel = new JPanel(new BorderLayout());
panel.add(toolbar, BorderLayout.PAGE_START);
panel.add(label, BorderLayout.CENTER);
final JFrame frame = new JFrame();
frame.setJMenuBar(mb);
frame.add(panel);
frame.setTitle("Test");
frame.setSize(400,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
輸出,與Vista的Windows的原生應用程序相比:
雖然在測試應用程序菜單欄中的文本的大小正確,其餘的該文本比在其旁邊的本地應用程序中的文本更小。放大時,你可以看到,在測試程序文本的JLabel比原生應用程式短1px的:
這是在Windows籌集到的錯誤,還是我們濫用呢?如果這是一個錯誤,是否有一個已知的解決方法?
對我來說,看起來好像Swing L&F使用不同的字體。 –
+1準備好的問題。 –