简体   繁体   English

在Netbeans / Java Swing下,如何以GTK +外观运行程序?

[英]Under Netbeans/Java Swing, how do I run the program as GTK+ Look and Feel?

I've been trying to Google this answer with no results. 我一直在尝试谷歌这个答案,没有结果。 I keep on finding answers on how to make Netbeans run in a GTK skin .... this is NOT what I want. 我一直在寻找有关如何使Netbeans在GTK皮肤中运行的答案....这不是我想要的。

I have a Java Swing application. 我有一个Java Swing应用程序。 I can preview it under GTK+, C/X Motif perfectly fine when I right click the JPanel Form --> Preview. 当我右键单击“ JPanel表单”->“预览”时,可以在GTK +,C / X Motif下完美预览。 However, whenever I try to run the program (build + run), the resulting GUI is a Java Swing look and feel. 但是,每当我尝试运行程序(build + run)时,生成的GUI都是Java Swing外观。

How do I permanently enable GTK+ for this program? 如何为该程序永久启用GTK +?

You have to set the Look and Feel according to the native look and feel. 您必须根据本地的外观来设置外观

The following code must be ran when your app starts up. 您的应用启动时必须运行以下代码。

public static void setLookAndFeel() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) {
      System.out.println("Error setting native LAF: " + e);
    }
}

在Projects Explorer中,右键单击项目节点,选择Properties,转到Application-> Desktop App节点,选择所需的Look&Feel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM