0

Javaのルックアンドフィールに問題があります。

mainメソッドで次のコードを使用してNimbusスキンに設定しました。

public class Main
{
    public static void main(String[] args)
    {
        try
        {
            boolean found = false;
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
            {               
                if ("Nimbus".equals(info.getName()))
                {
                    UIManager.setLookAndFeel(info.getClassName());
                    found = true;
                    break;
                }
            }

            if (!found) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues"));
        }
        catch (Exception e) {}

        Manager mngr = new Manager();
        mngr.setSize(1000, 600);
        Utils.centerWindow(mngr);
        mngr.setVisible(true);
    }
}

そしてそれは私にこの種の窓を与えます:

ここに画像の説明を入力してください

ご覧のとおり、JInternalFramesは正しくスキンされていますが、メインウィンドウは正しくスキンされていません。

このウィンドウにもテーマを適用するにはどうすればよいですか?

ありがとう。


ManagerJFrame次のコードを使用した単純なものです。

public class Manager extends JFrame
{
    public Manager()
    {
        initComponents();
    }

    private void initComponents()
    {
        setDefaultCloseOperation(3);
        setTitle("My window");
        setIconImage(ImageLoader.getIcon().getImage());

        // My components go here

        pack();
    }
}
4

3 に答える 3

3
于 2012-04-20T13:44:01.357 に答える
0

さて、私は良いSSCCEなしであなたのために何をすべきかわかりませんが、私のために常に機能するメソッドの例が必要な場合は、 githubのJava-Helperを見ることができます。具体的には、この行のSwingHelperを見てください。スタックオーバーフローの基本ルールのいくつかに準拠するために、以下のコードを追加しています;)幸運を祈ります。

  /**
   * Sets the look and feel to the given type (like "Nimbus") Learn more here:
   * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
   *
   * @param lookAndFeel to set (like "Nimbus")
   */
  public static void setLookAndFeel(String lookAndFeel) {
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ((info.getName()).equals(lookAndFeel)) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(SwingHelper.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
  }
于 2012-04-20T16:27:28.670 に答える
0

フレーム/ダイアログを作成する前に、次の2つのオプションをオンにしてみてください。

JDialog.setDefaultLookAndFeelDecorated ( true );
JFrame.setDefaultLookAndFeelDecorated ( true );

これにより、JFrame/JDialogはシステムではなくLaFから装飾を取得できるようになります。

于 2012-04-20T16:49:20.617 に答える