Search code examples
javafontsawtgraphics2d

Why is the int in the Font constructor not changing the font size while painting the string?


My problem is where you see the Font constructor, the last term is the font size integer, and whether it says 12 or 100(like now) it still prints the text at the same size. What am I doing wrong.

@Override
    protected void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        Font font = new Font(Font.SERIF, Font.PLAIN, 100);

        if(setTextAttributes){
            setTextAttributes();
            setTextAttributes = false;
        }

        c.paintCursor( g2d );

        font = font.deriveFont(map);
        g2d.setFont(font);
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                             RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        g2d.drawString(text, lineX, lineY);

    }

Solution

  • The line font.deriveFont(map) creates new font as it's said in docs