gpt4 book ai didi

java - 如何使 swing 应用程序具有 dark nimbus 主题 netbeans

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:53:58 26 4
gpt4 key购买 nike

所以我是 Netbeans 和 Swing GUI 开发的新手,我正在尝试更改 JFrame 的外观。当我创建一个 JFrame 表单时,Netbeans 默认将其设为 Nimbus 主题。

我尝试更改为 Windows 主题 (if ("Windows".equals(info.getName())) {) 和 Metal 主题 (if ("Metal". equals(info.getName())) {) 并且它完美地处理了这两个主题。

但是当我尝试将其更改为 Dark Nimbus 主题时 (if ("Dark Nimbus".equals(info.getName())) {) 它不起作用。

我也尝试过右击 > 预览设计 > Dark Nimbus,是的,它按预期预览了 Dark Nimbus 主题。但是当我实际编译和运行程序时(通过单击播放按钮)。

有谁知道如何将主题更改为“Dark Nimbus”?

相关代码如下:

    /* 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 ("Dark Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TestGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TestGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TestGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TestGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>

最佳答案

我最近也有同样的担忧,我从 Geertjan Wielenga 中找到了这些极好的提示来自Neil C Smith .所以你的问题的答案是:

public static void main(String[] args) {
UIManager.put( "control", new Color( 128, 128, 128) );
UIManager.put( "info", new Color(128,128,128) );
UIManager.put( "nimbusBase", new Color( 18, 30, 49) );
UIManager.put( "nimbusAlertYellow", new Color( 248, 187, 0) );
UIManager.put( "nimbusDisabledText", new Color( 128, 128, 128) );
UIManager.put( "nimbusFocus", new Color(115,164,209) );
UIManager.put( "nimbusGreen", new Color(176,179,50) );
UIManager.put( "nimbusInfoBlue", new Color( 66, 139, 221) );
UIManager.put( "nimbusLightBackground", new Color( 18, 30, 49) );
UIManager.put( "nimbusOrange", new Color(191,98,4) );
UIManager.put( "nimbusRed", new Color(169,46,34) );
UIManager.put( "nimbusSelectedText", new Color( 255, 255, 255) );
UIManager.put( "nimbusSelectionBackground", new Color( 104, 93, 156) );
UIManager.put( "text", new Color( 230, 230, 230) );
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (javax.swing.UnsupportedLookAndFeelException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
// Show your JFrame
}

关于java - 如何使 swing 应用程序具有 dark nimbus 主题 netbeans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com