到目前为止,我有这个
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,但更改标题边框为窗口。
我的边界是这样的:
contentPanel.setBorder(new TitledBorder("Downloader"));有可能这样做吗?如果是的话,有人能告诉我去哪里找吗?我现在很困惑。:\
谢谢。
发布于 2011-01-17 04:20:18
我已经做到了。您必须创建部分UI,然后调用UIManager.setLookAndFeel()来更改外观,然后创建其他部分。它更像是一个黑客。
发布于 2013-08-25 09:27:14
创建Component时,当前LookAndFeel将用于显示该Component。
发布于 2018-08-18 14:07:28
我知道我来晚了,但我想可能有人在用这个,这是我用来把多个外观和感觉放到应用程序中的一种技巧:在启动项目之前,把这个放在外观和感觉选择器上(在编写= 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();
}这样,只有按钮测试将具有窗口的外观和感觉,其余的将具有Metal的外观和感觉。
希望这篇文章能帮到什么人。
https://stackoverflow.com/questions/4707716
复制相似问题