Handout: Fonts in Java


When you use a setFont() method to tell Java what font you want to use, you have to put something in the brackets to specify the font. The thing you put in the brackets will create a new font for Java to use.


You create a new font to use like this:

new Font(name, style, size)









Any positive


            Serif = Times New Roman on most computers

            SansSerif = Arial on most computers

     MonoSpaced = Courier New on most computers



            new Font(“Serif”, Font.PLAIN, 12)     


        new Font(“SansSerif”, Font.ITALIC, 16)


       new Font(“MonoSpaced”, Font.BOLD, 8)


You tell the Console to use your new font like this:


            c.setFont(new Font(name, style, size) );


            The console will now use your new font with the specified name, style, and size



                    c.setFont(new Font(“Serif”, Font.BOLD, 12) );


             c.setFont(new Font(“SansSerif”, Font.PLAIN, 15));


          c.setFont(new Font(“MonoSpaced”, Font.ITALIC, 10));