سؤال

I'm trying to change globaly the size of my tooltips.

I'm using :

UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25));

Which work just fine in general. But in my case, I'm using Nimbus LaF with this code :

    UIManager.LookAndFeelInfo plafinfo[] = UIManager.getInstalledLookAndFeels();
    boolean LaFfound=false;
    int LaFindex=0;

    for (int look = 0; look < plafinfo.length && !LaFfound; look++)
    {
        if(plafinfo[look].getClassName().toLowerCase().contains("nimbus"))
        {
            LaFfound=true;
            LaFindex=look;
        }
    }

    try {
        if(LaFfound) {
            UIManager.setLookAndFeel(plafinfo[LaFindex].getClassName());
        }
        else {UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());}
    }
    catch(Exception e){Logger.getLogger(Fenetre.class.getName()).log(Level.SEVERE, null, e);}

    //correct tooltips size
    UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25));

In this case, the UIManager seems to completely ignore my instruction, as if "ToolTip.font" was not an admitted property in Nimbus LaF...

But according to this page : http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html this property exists.

What's wrong with my code ? Or how can I fix this with an other way ?

Thanks a lot !

هل كانت مفيدة؟

المحلول

Nimbus appears to work differently than other LAF's. You need to set the property before you set the LAF:

UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25));

try
{
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
    {
        if ("Nimbus".equals(info.getName()))
        {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
}
catch (Exception e)
{
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

With other LAFs I believe you can change any property before you create the first component of that type.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top