【问题标题】:How to change the LookAndFeel of the NetBeans Platform Framework Application如何更改 NetBeans 平台框架应用程序的 LookAndFeel
【发布时间】:2012-07-24 18:25:02
【问题描述】:

我不知道如何更改我在 NetBeans 平台框架上构建的应用程序的 LookAndFeel,有人可以帮忙吗?我想使用 TinyLAF java api http://www.muntjak.de/hans/java/tinylaf/index.html 改变它的外观。我知道在 NetBeans IDE 中开发常规 Swing 应用程序时如何更改 LookAndFeel,但在 NetBeans 平台框架上开发时不知道。

这是我用于常规 Swing 应用程序的 TinyLAF 代码:

Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);

try {
    UIManager.setLookAndFeel("de.muntjak.tinylookandfeel.TinyLookAndFeel");
} catch(Exception ex) {
    ex.printStackTrace();
}

TinyLaF 会查找名为“Default.theme”(区分大小写)的默认主题文件。如果它找到一个,这个文件将在启动时加载。 ('Default.theme' 文件是一个普通的 TinyLaF .theme 文件,只是有一个特殊的名字,你可以把任何 .theme 文件重命名为'Default.theme')。

TinyLaF 将搜索以下 URL:

  1. TinyLookAndFeel.class.getResource("/Default.theme");
    • 如果在 tinylaf.jar 中,则找到“Default.theme”
  2. Thread.currentThread().getContextClassLoader().getResource("Default.theme");
    • 如果“Default.theme”在您的应用程序的 JAR 中,则会找到它
  3. 新文件(System.getProperty("user.home"), "Default.theme").toURI().toURL();
    • 如果 'Default.theme' 在主目录中,则查找它
  4. 新文件(System.getProperty("user.dir"), "Default.theme").toURI().toURL();
    • 如果 'Default.theme' 在工作目录中,则找到它

请注意,我的问题不是如何更改 NetBeans IDE 的 LookAndFeel,而是如何为构建在 NetBeans Platform 框架之上的 Java 应用程序进行更改。

【问题讨论】:

    标签: java swing netbeans-7 look-and-feel netbeans-platform


    【解决方案1】:

    我在网上找到了以下内容:您需要在“安装程序”模块中进行。 检查此链接以了解您需要添加的位置:http://joshiegeek.blogspot.co.il/2012/01/netbeans-platform-custom-laf.html

    这个有实际的代码示例(请忽略标题:)):http://forums.netbeans.org/topic39450.html

    最后,这个讨论了一个特定的 plaf,但沿途很少有 cmets:https://blogs.oracle.com/geertjan/entry/blue_look_and_feel_for

    【讨论】:

    • 非常感谢。解决方案在第一个链接中。
    • 第一个链接已失效。我希望你能多说一点它过去所说的......
    • @Christopher Bruns 我发布链接是为了不带来全部内容。无论如何,再次搜索我发现:devblog.virtage.com/2011/09/… 检查“NetBeans 平台应用程序”部分,解决方案是一行。我不知道它与其他方式相比如何,但我希望这对你的情况有所帮助。
    • @A.J.很抱歉,您发布的第一个链接和您在评论中发布的链接都无法从此处打开。 :(
    【解决方案2】:

    1.您可以非常轻松地更改 Swing 的外观,因为它基于 MVC 架构。

    2. Swing 也称为PLAF (Pluggable Look And Feel),因此保持相同的模型部分并更改视图,例如桌面和 Web 应用程序的相同模型。

    3.使用

    UIManager.setLookAndFeel(Your_Choice_of_Look_and_Feel);  // To set the Look and Feel
    SwingUtilities.updateComponentTreeUI(frame);        // To refresh the JFrame and Components
    

    更多详情请参见:

    http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

    【讨论】:

    • 我猜 OP 已经知道这一点,因为他提到了他用于常规摆动应用程序的代码。他想知道如何为在 Netbeans 平台上运行的应用程序执行此操作。
    • 他需要在 GUI 代码中手动更改它,正如我上面提到的......我希望他使用的是 netbeans 团队在 2005 年开发的 GroupLayout。这样可以更轻松地安排组件跨度>
    【解决方案3】:

    必须找到之前关于waybackmachine 的帖子中提到的第一个链接...

    答案是添加运行时参数或将其放入 project.properties 文件中。要添加的行(例如金属)是

    run.args.extra=--laf javax.swing.plaf.metal.MetalLookAndFeel
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多