代码之家  ›  专栏  ›  技术社区  ›  Samurai

在Java应用程序中添加外观

  •  2
  • Samurai  · 技术社区  · 15 年前

    我正在和 NetBeans 6.5 IDE .

    我下载了一个look-and-feel jar文件,并通过palette manager添加了netbeans。

    如何在应用程序中使用它?

    2 回复  |  直到 12 年前
        1
  •  3
  •   VonC    15 年前

    您可以按照本Sun教程 setting the L&F in Java

    您可以使用 setLookAndFeel 即使程序的gui是可见的。
    要使现有组件反映新的L&F,请调用 SwingUtilities updateComponentTreeUI 方法,每个顶级容器一次。
    然后,您可能希望调整每个顶级容器的大小,以反映其所包含组件的新大小。例如:

    UIManager.setLookAndFeel(lnfName);
    SwingUtilities.updateComponentTreeUI(frame);
    frame.pack();
    
        2
  •  2
  •   Samurai    15 年前

    谢谢你的回复。 通过使用下面的代码,我们可以得到所有的外观类名。

    UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
        for (int i = 0; i < lookAndFeelInfos.length; i++) {
            UIManager.LookAndFeelInfo lookAndFeelInfo = lookAndFeelInfos[i];
    
            //
            // Get the name of the look and feel
            //
            String name = lookAndFeelInfo.getName();
            System.out.println("name = " + name);
    
            //
            // Get the implementation class for the look and feel
            //
            String className = lookAndFeelInfo.getClassName();
            System.out.println("className = " + className);
        }
    
    推荐文章