2

到目前为止我有这个

public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            UIManager.getBorder("design");//change look and feel here?
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Nimbus isn't available");
        }
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                design GUI = new design();
                GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                GUI.setVisible(true);
            }
        });
    }

我正在尝试制作主要的外观和感觉 nimbus,但将标题边框更改为 windows。

我的边界是这样的:

contentPanel.setBorder(new TitledBorder("Downloader"));

有可能吗?如果是有人可以指出我在哪里看?我现在很困惑。:\

谢谢。

4

3 回答 3

2

我已经做到了。您必须创建部分 UI,然后调用 UIManager.setLookAndFeel() 来更改外观,然后再创建其他部分。这更像是一个黑客。

于 2011-01-16T20:20:17.567 回答
0

创建a 时Component,当前LookAndFeel将用于显示该Component.

于 2013-08-25T01:27:13.567 回答
0

我知道我迟到了,但我认为有人可能会使用它,这是我用来为应用程序添加多种外观的一种技巧:在启动项目之前将其作为外观选择器(在编写之前 = new ... )

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

然后将 UIManager 外观返回到在您执行此操作之前它处于打开状态的外观,如下例所示:

JButton test;
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
test = new JButton();
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Mwtal".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
    | UnsupportedLookAndFeelException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

像这样只有按钮测试将具有窗口的外观和感觉,其余的将具有金属的外观和感觉。

希望这个黑客可以帮助某人。

于 2018-08-18T06:07:28.190 回答