1

ツールチップのサイズをグローバルに変更しようとしています。

私は使用しています:

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

これは一般的にうまく機能します。しかし、私の場合、次のコードで Nimbus LaF を使用しています。

    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));

この場合、「ToolTip.font」が Nimbus LaF で許可されたプロパティではないかのように、UIManager は私の指示を完全に無視しているようです...

しかし、このページによると: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.htmlこのプロパティは存在します。

私のコードの何が問題になっていますか? または、これを別の方法で修正するにはどうすればよいですか?

どうもありがとう !

4

1 に答える 1

0

Nimbus は、他の LAF とは動作が異なるようです。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.
}

他の LAF では、そのタイプの最初のコンポーネントを作成する前に、任意のプロパティを変更できると思います。

于 2013-05-21T02:00:26.470 に答える