JLabel vertical alignment not working as expected

前端 未结 2 1127
失恋的感觉
失恋的感觉 2021-01-17 11:22
Font font = Font(\"Arial\", Font.BOLD, 35);

JLabel label = new JLabel(\"57\");
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS         


        
2条回答
  •  庸人自扰
    2021-01-17 11:30

    The arrow in your diagram points to the difference between the glyph's nominal ascent and the maximum ascent, as discussed in FontMetrics. You can tinker with setBorder(null); but for absolute control, you'll have to render the glyphs yourself, as shown here. Fortunately, the digit glyphs of most fonts have a uniform advance and ascent.

提交回复
热议问题