# Solved: JAVA: How to set FONT Correctly ?



## sepala (May 20, 2010)

Hi all,

Whenever I use the Font property in JAVA, I use this method,

*f1 = new Font("Arial Black",Font.BOLD,20);*

The only thing I change is Font Family, size and its behavior(Bold, italic), because otherwise it gives errors. For an example, I tried to use font without the Bold option like this

*f1 = new Font("Arial Black",20);*

But this gave me an error. I think I don't know how to use this font property correctly. Please help me.


----------



## andythepandy (Jul 2, 2006)

Font - http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Font.html

You must give the arguments in the order they are in the declaration:

```
Font(String name, int style, int size)
```
That means you need to give all three arguments in that order, and you can't skip any.
You could create your own method which only takes name and size (or just size if you are always using the same font family)

```
Font makeFont(String name, int size)
{
	return new Font(name, Font.BOLD, size);
}

Font makeFont(int size)
{
	return new Font("Arial Black", Font.BOLD, size);
}

...

Font f1 = makeFont("Arial Black", 20);

//or

Font f1 = makeFont(25);
```


----------



## sepala (May 20, 2010)

Cool!!! Thanks andy!!


----------

