Andrew Smith
Andrew Smith

Reputation: 21

How to set the font, type, and size of a String when printing to the console?

So I am a very new Java programmer attempting to create an ASCII art image using loops and I am wondering how I can change the font type, and if I am required to use a Font object, this is the object i would use

Font myFont = new Font("Courier New",Font.PLAIN, 6);

Seeing as I created the ASCII art using Courier New size 6, I would like to make sure that the output shown on the user's screen will also be Courier new size 6. How would I be able to do this in the code itself?

Upvotes: 1

Views: 4321

Answers (1)

axiopisty
axiopisty

Reputation: 5155

If you are printing to System.out on the console, you can't specify the font. In that case the font is specified by the console itself.

The Font object referred to in the OP is used for GUIs like AWT, Swing, SWT or JavaFX. If you're creating a GUI then you can specify the font with the code snippet in the OP. You would use the font on, say for example, a JLabel or JButton in swing.

If you're wanting to create ASCII art in swing, then you could set the specified font on a JTextArea. Search the JTextArea API for setFont.

Upvotes: 2

Related Questions