Java – why does windows lookandfeel make fonts too small?

Native windows lookandfeel in Java 6 seems to have incorrectly resized some fonts

Test procedure:

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);
      }
    });
  }
}

Compare the output to the native Windows Application on Vista:

Although the text in the test application menu bar is the correct size, the rest of the text is smaller than the native application next to it When you zoom in, you can see that the text in the test application jlabel is shorter than the native application 1px:

Is this an error in Windows LAF, or are we abusing it? If this is an error, is there a known solution?

Solution

Java 6 uses its own font renderer, including the implementation of sub-pixel anti aliasing / hint Whatsit Although the output is similar to windows rendering, the top of B is at the pixel boundary, or it is circular, or both, throw out the Java renderer The Windows font renderer decides to place the top of the letter above the boundary and the Java font below the boundary‘ L 'looks at the same height in both samples, so the renderer doesn't look like every letter has the wrong height Maybe try comparing some letters with a straight line at the top, such as t or e?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>