我需要采取哪些步骤来改变Java Swing GUI的外观和感觉?

3
我刚刚发现了一个外观不错的界面,想在我的程序中使用它,但我不确定如何集成。这是我想要的界面:AcrylLookAndFeel 我已经找到了网站并下载了一个jar文件,将其包含在了我的构建路径中。我还找到了以下代码行,并将其加入了我的程序中:
UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");

我运行程序时没有任何错误,但它看起来与图片完全不同。我错过了什么步骤吗?我需要做什么?

我还有一个问题,我目前在使用mac电脑开发程序,但无论将程序在mac或windows上运行,我都希望界面保持一致。这是否可能实现?如果是,请告诉我如何操作(是否需要进行任何更改)。


你在代码中放置了 UIManager 语句吗?此外,图像并不一定与你所问的问题相关,但是你设置它作为你的 LAF 的代码存在和不存在。 - Brandon Buck
1
对于一些需要 L&F 的情况,在 UIManager.setLookAndFeel() 之后添加代码行 SwingUtilities.updateComponentTreeUI(frame); - mKorbel
@mKorbel,很好的决定,第一个识别出根本问题的解决方案。我在我的评论中链接了一个示例,供采纳答案者参考。 - Andrew Thompson
3个回答

2

在Java中设置Swing外观和感觉会在不同操作系统之间保持一致。在创建Swing GUI之前,我总是只做这件事。

public static void main(String[] args) {
    try {    
        UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
    } 
    // Probably want to break this into handling the various exceptions that can be thrown.
    catch (Exception e) {
       // handle exception
    }

    // Create Swing GUI and so forth
}

谢谢你的帮助 - 事实证明问题出在代码的顺序上。在创建GUI组件之前,我需要设置外观和感觉。 - user843337
3
只要GUI被正确更新,代码行在哪里被调用并不重要。请查看“嵌套布局示例”以获取可以在运行时更改PLAF(用户想要更改多少次都可以)的GUI。链接 - Andrew Thompson

0
import org.jvnet.substance.SubstanceLookAndFeel;

public class Main {

    public static void main(String[] args) {
       /*Si no se tiene instalado la libreria Substance*/
       //formpadre fp= new formpadre();
       //fp.show();

        /*si la libreria substance esta instalada y configurada*/               
        EventQueue.invokeLater(new Runnable(){
        public void run(){
            try{
                JFrame.setDefaultLookAndFeelDecorated(true);                
                SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.BusinessBlueSteelSkin");            //SubstanceLookAndFeel.setCurrentTheme("org.jvnet.substance.theme.SubstanceAquaTheme");   
            }              
            catch(Exception e){
            }               
            new formpadre().setVisible(true);
        }
        });            
    }
}

0
在创建JFrame之前:
// setup the look and feel properties
Properties props = new Properties();

// set your theme
SmartLookAndFeel.setCurrentTheme(props);
// select the Look and Feel
UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");

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