# Setting Default Font

**URL:** <https://forum.juce.com/t/setting-default-font/21633>\
**Category:** General JUCE discussion\
**Created:** [April 3, 2017, 7:46pm UTC](https://forum.juce.com/t/setting-default-font/21633 "2017-04-03T19:46:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![timart](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/timart/32/1119_2.png) [@timart](https://forum.juce.com/u/timart)\
**Post date:** [April 3, 2017, 7:46pm UTC](https://forum.juce.com/t/setting-default-font/21633/1 "2017-04-03T19:46:08Z")

</div>

I’ve checked the forum for this, but it seems none of the current solutions are working for me.

I want to set a default font for all components to use, so in my custom `LookAndFeel` class’ constructor I wrote `setDefaultSansSerifTypefaceName("Avenir Next");` but this does not change the font.

The other functions in my `LookAndFeel` are working as expected. Also, the font exists on my system and works when I set the font for individual components.  
Thanks!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 4, 2017, 8:31am UTC](https://forum.juce.com/t/setting-default-font/21633/2 "2017-04-04T08:31:30Z")

</div>

When I add this line to the projucer’s initialise method:

```
    LookAndFeel::getDefaultLookAndFeel().setDefaultSansSerifTypefaceName ("Avenir Next");

```

it works.

So you must be doing something silly. e.g. probably modifying a different look+feel object to the one you’re using.

---

<div class="post-metadata">

**Author:** ![timart](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/timart/32/1119_2.png) [@timart](https://forum.juce.com/u/timart)\
**Post date:** [April 4, 2017, 3:52pm UTC](https://forum.juce.com/t/setting-default-font/21633/3 "2017-04-04T15:52:29Z")

</div>

Thanks Jules!  
This does indeed work for me as well.

Although, I would’ve expected the `setDefualtSansSerifTypefaceName` call to work in the constructor of my custom LookAndFeel. The rest of my custom LookAndFeel works as expected within my application except for this call. For example here’s a summary of what my code looks like:

## CustomLookAndFeel.h

```
class CustomLookAndFeel : public LookAndFeel_V3
{
public:
    CustomLookAndFeel()
    {
        setDefaultSansSerifTypefaceName ("Avenir Next"); // This call doesn't work
    }
    
    // The rest of my LookAndFeel which does work . . .
};

```

## MainComponent.cpp

```
class MainContentComponent : public Component
{
public:
    MainContentComponent()
    {
        setLookAndFeel (&customLookAndFeel);
    }

    // The rest of the class . . . 

private:
    CustomLookAndFeel customLookAndFeel;
};

```

I’m probably just fundamentally misunderstanding something about this.

Thanks again for your solution though! I will definitely be using that solution. I just wanted to clarify my understanding about what I was trying to do earlier with the LookAndFeel Constructor.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 4, 2017, 4:42pm UTC](https://forum.juce.com/t/setting-default-font/21633/4 "2017-04-04T16:42:08Z")

</div>

Only the global L+F is used for this.

(How else could the Font objects all over the codebase know that you were expecting them to use this customLookAndFeel instance that you created?)

---

<div class="post-metadata">

**Author:** ![timart](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/timart/32/1119_2.png) [@timart](https://forum.juce.com/u/timart)\
**Post date:** [April 4, 2017, 4:59pm UTC](https://forum.juce.com/t/setting-default-font/21633/5 "2017-04-04T16:59:25Z")

</div>

Okay I see. Thanks for your help Jules!

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [April 6, 2017, 6:33pm UTC](https://forum.juce.com/t/setting-default-font/21633/6 "2017-04-06T18:33:21Z")

</div>

> [@jules](#):
>
> (How else could the Font objects all over the codebase know that you were expecting them to use this customLookAndFeel instance that you created?)

Well, you could expect that all the Component’s that have your custom LookAndFeel class would use the Font right? I mean it’s a member method of the LookAndFeel class and it’s not a static one so the assumption is not so un-logical is it?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 6, 2017, 7:13pm UTC](https://forum.juce.com/t/setting-default-font/21633/7 "2017-04-06T19:13:19Z")

</div>

Well no - think about the code you actually write. E.g. if you create a font object

```
Font myFont (15.0f);

```

… then like I said above, how could it possibly know which component to get the L+F from? What if you have two different components with two L+Fs and use this same font object in both of them?

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [April 6, 2017, 7:19pm UTC](https://forum.juce.com/t/setting-default-font/21633/8 "2017-04-06T19:19:55Z")

</div>

True that makes sense, but i think the OP was expecting that his JUCE Buttons or Labels would start using the Font he specified in his Custom LookAndFeel.  
I know you can override all the draw methods and do anything you like but i can understand why he is confused. You told him he was probably doing something ‘silly’…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 6, 2017, 7:26pm UTC](https://forum.juce.com/t/setting-default-font/21633/9 "2017-04-06T19:26:32Z")

</div>

Sure, I understand why you’d expect it to happen.

> [@Rebbur](#):
>
> You told him he was probably doing something ‘silly’…

Well, yes, but to be fair if I’d seen the same symptoms in my own code, my first reaction would also have been to assume I’d made a silly mistake. Everyone makes silly mistakes, it’s not a criticism!

---

<div class="post-metadata">

**Author:** ![jbsolutions2008](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jbsolutions2008](https://forum.juce.com/u/jbsolutions2008)\
**Post date:** [April 18, 2020, 7:43am UTC](https://forum.juce.com/t/setting-default-font/21633/10 "2020-04-18T07:43:56Z")

</div>

i have set this way but unable to set the font. is there any font ttf required in assets folder or juce will take it from library. I am new please help

---

<div class="post-metadata">

**Author:** ![yoogle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yoogle/32/14955_2.png) [@yoogle](https://forum.juce.com/u/yoogle)\
**Post date:** [April 7, 2023, 6:53am UTC](https://forum.juce.com/t/setting-default-font/21633/11 "2023-04-07T06:53:27Z")

</div>

Setting the lookAndFeel globally via

```auto
juce::LookAndFeel::setDefaultLookAndFeel(&customLNF);

```

is breaking in multiple instance of plugins. If I close the other instance of plugin, the look and feel of first plugin will be gone.

I tried setting the look and feel on the main editor, then the same problem is coming as mentioned on the top question, typeface not utilised. What will be the correct solution ?
