如何安装/配置自定义Java外观?

5
我正在尝试安装Sea Glass外观。我想使用属性文件来安装/配置LaF,但是这个过程的教程相当令人困惑。
鉴于上述情况,请问有没有人能够提供一个简单的分步指南,告诉我如何使用属性文件安装/配置自定义LaF?
3个回答

6

来自他们的网站:

要使用Sea Glass外观和感觉,您必须在pom.xml文件中包含我们的Maven存储库,或下载jar文件并将其包含在类路径中。有关更多详细信息,请参见下载页面。

要启用Sea Glass外观和感觉,在创建任何控件之前,请在您的应用程序中包含以下内容:

try {
    UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
} catch (Exception e) {
    e.printStackTrace();
}

我们还支持使用VM选项在命令行上设置用户界面。
-Dswing.defaultlaf=com.seaglasslookandfeel.SeaGlassLookAndFeel

4
以下是使用jar文件安装Sea Glass L&F的步骤(请注意,我使用的是eclipse,因此以下指令是基于eclipse的):
  1. Download the LaF jar file in their Maven repository.
  2. Put the .jar file in a designated folder in your project
  3. Right click your project folder in eclipse the go to 'Build Path' then select 'Configure Build Path'
  4. Under Libraries tab, click 'Add External Jar' and go to the folder that contains the jar file
  5. Click Ok then in your code go to your public static void main(String[] args) and copy paste this snippet:

    try {
        UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    

现在,L&F已经应用了。如果您有问题,请随时询问。


2
我在NB IDE中运行它没有任何问题。

enter image description here

从代码中。
import java.awt.*;
import javax.swing.*;
//import javax.swing.plaf.InsetsUIResource;

public class NimbusJPanelBackGround {

    public NimbusJPanelBackGround() {
        JFrame f = new JFrame();
        JButton btn = new JButton("  Whatever  ");
        JButton btn1 = new JButton("  Whatever  ");
        JPanel p = new JPanel();
        p.add(btn);
        //UIManager.getLookAndFeelDefaults().put("Button.contentMargins", new InsetsUIResource(0, 0, 0, 0));
        //SwingUtilities.updateComponentTreeUI(f);
        p.add(btn1);
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.add(p, BorderLayout.CENTER);
        f.setSize(200, 100);
        f.setLocation(150, 150);
        f.setVisible(true);
    }

    public static void main(String[] args) {

        /*try {
        for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(laf.getName())) {
        UIManager.setLookAndFeel(laf.getClassName());
        UIManager.getLookAndFeelDefaults().put("Panel.background", Color.white);
        }
        }
        } catch (Exception e) {
        e.printStackTrace();
        }*/

        try {
            UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
        } catch (Exception e) {
            e.printStackTrace();
        }


        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                NimbusJPanelBackGround nimbusJPanelBackGround = new NimbusJPanelBackGround();
            }
        });
    }
}

编辑:

由于Substance L&F模拟器需要用户声望> 10k才能查看我的答案,因此社区将其删除,因为它不是一个答案:-)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接