How to auto-adjust font size of multiple JLabel based on container size in a smooth way?

前端 未结 3 1703
Happy的楠姐
Happy的楠姐 2020-12-11 05:10

I need to resize the font of multiple JLabel based on the scaling factor used to resize the container. To do this, I am setting the font of each JLabel to null so that they

3条回答
  •  佛祖请我去吃肉
    2020-12-11 05:55

    I sort of solved the problem adding:

    @Override
    protected void paintComponent(Graphics g) {
        final Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        g2d.setRenderingHint(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        super.paintComponent(g2d);
    }
    

    Thanks anyway.

提交回复
热议问题