【发布时间】:2020-04-27 12:17:16
【问题描述】:
我想改变 jframe 的外观。我使用网豆。于是我去找了jframe的源码,改了main方法在windows的look and feel中打开jframe。
下面是代码。它是由 netbeans 生成的,我改变了这一行
if ("Nimbus".equals(info.getName()))
改完后是这样的if ("Windows".equals(info.getName()))
这是由netbeans生成的main方法的完整代码。
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TextEditorGui().setVisible(true);
}
});
}
将 Nimbus 更改为 Windows 后,我运行文件 按 shift + f6,它使 jframe 具有 Windows 外观。但是当我按 F6 运行文件时,它给了我 Metal 的外观。是的,正是金属外观。不是 nimbus 外观.. 我想将其更改为 windows 外观。怎么做??请帮帮我...
【问题讨论】:
-
如果您更改了它要查找的名称,但它找不到确切的名称,那么它不会调用
setLookAndFeel并回退到默认值(我认为 仍然是 金属,即使过了这么多年)。打印出它循环的名称以找出可用的名称。 -
实际上我打印了名称并得到了这个列表 Metal Nimbus CDE/Motif Windows Windows Classic
标签: java swing user-interface