- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试调整 Nimbus 外观的颜色,但它只是部分起作用。特别是我在调整菜单栏的颜色时遇到了问题。
这是一个运行示例:
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
public class JMenuColorTest extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
adjustLAF();
} catch (Exception e) {
e.printStackTrace();
}
JMenuColorTest test = new JMenuColorTest();
test.setDefaultCloseOperation(EXIT_ON_CLOSE);
test.setPreferredSize(new Dimension(400, 300));
test.pack();
test.setLocationRelativeTo(null);
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu("Menu 1");
menu1.add(new JMenuItem("Item 1.1"));
menu1.add(new JMenuItem("Item 1.2"));
menu1.add(new JMenuItem("Item 1.3"));
menuBar.add(menu1);
JMenu menu2 = new JMenu("Menu 2");
menu2.add(new JMenuItem("Item 2.1"));
menu2.add(new JMenuItem("Item 2.2"));
menu2.add(new JMenuItem("Item 2.3"));
menuBar.add(menu2);
test.setJMenuBar(menuBar);
test.setVisible(true);
}
private void adjustLAF() throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
// Working
UIManager.put("control", Color.GREEN);
// Not working
UIManager.getLookAndFeelDefaults().put(
"MenuItem[Enabled].textForeground", Color.RED);
// Set the look and feel
UIManager.setLookAndFeel(info.getClassName());
// Not working
UIManager.put("control", Color.GREEN);
// Working
UIManager.getLookAndFeelDefaults().put(
"MenuItem[Enabled].textForeground", Color.RED);
break;
}
}
}
});
}
}
如您所见,我能够设置控件的背景并设置 JMenuItem 的前景色。但是我无法更改 JMenuItem 的背景,也无法更改 MenuBar 的颜色。我尝试了很多来自 http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html 的键但我无法更改菜单栏的颜色。
另一个问题是?为什么我必须在设置 Look and Feel 之前和设置 Look and Feel 之后调用一次颜色调整?为什么我必须调用一次“UIManager.put()”和一次“UIManager.getLookAndFeelDefaults().put()”?
在我看来,Nimbus 确实有问题,不适合专业使用。我尝试同时使用 JDK 1.6.35 和 JDK 1.7.7,但是对于这两个 JDK,我无法让系统按预期运行?
关于如何在 Nimbus LookAnd Feel 中调整菜单栏的颜色有什么建议吗?
提前致谢
最佳答案
JMenuBar
必须使用 Painter , 检查 NimbusDefault#value
MenuBar[Enabled].backgroundPainter
MenuBar[Enabled].borderPainter
休息由 trashgod +1
回答
关于java - Nimbus Look And Feel 调整菜单栏的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12369783/
我是 Java Nimbus 外观和感觉 的新手。我正在尝试使用 Nimbus 的功能来自定义单个组件实例,使用 putClientProperty("Nimbus.Overrides", overr
我正在使用 java 7 update 17 和 netBeans IDE 7.3 我想将 nimbus 设置为每个 GUI 项目的默认值,但 Oracle 网站指令不起作用。 how to set
我正在制作一个程序,该程序应该尽可能独立于平台。我正在使用 Nimbus LAF。 我想知道,我应该担心字体吗?它的默认字体是包含在 LAF 本身中还是从平台获取? 最佳答案 这是默认的非系统字体。
如何自定义 Nimbus 外观中组件的图像?我想在 Photoshop 中创建图像并放置在一些 Nimbus 外观和感觉组件上,这些是我想要更改的组件: 滚动条按钮旋钮滚动条拇指滚动条滚动条轨道 谢谢
在 Nimbus 的网络照片应用程序示例中,当我返回表格(从 Facebook 或 Dribbble 中选择要下载照片的位置)时,我之前看到的和缓存中的照片都会从其中清除。有办法防止这种情况吗? 例如
我想更改选项卡标题的颜色。 我尝试设置不同的属性,但没有任何变化。 在我的 main 中,我将属性 text 设置为白色,因此所有文本都是白色的。 现在我想更改一些组件文本,例如选项卡 Pane ,但
我已经创建了一个文本字段组件,里面有一个“x”按钮,可以清除该字段的文本。它在使用 Window 的系统外观和感觉(对于 Windows)时效果很好,但是我在使用 Nimbus 时尝试获得正确的外观时
引用这个错误: 4848910 : UIManager only updates colors once 我的 JFrame 上有两个按钮。从第一个按钮开始,我将 LAF 颜色更改为 UIManage
所以,我的程序中有一个使用 Nimbus LAF 的 JTextArea。由于一些功能问题,我需要将其替换为 JTextPane。 但是,JTextArea 默认情况下有一个绘制的边框。 JTextP
我正在使用 NIPagingScrollView在 iPhone 上显示多个页面。 每次我翻到一个页面,下一页也被预先加载,这很好。 当我旋转 iPhone从纵向模式到横向模式,我让layoutSub
我正在使用 Nimbus显示带有擦洗器和可缩放 ImageView 的相册。我使用网络图像,并在加载最终图像之前显示缩略图。 NIPhotoAlbumScrollView提供方法didLoadPhot
我正在尝试覆盖 JLabel 的一些 nimbus 属性。 UIDefaults labelDefault = new UIDefaults(); labelDefault.put("Labe
刚接触java,有一个问题,无论我做什么似乎都无法解决,所以任何我们将非常感谢您的帮助。 我有一个Java小应用程序,并集成了一个弹出日历(WWW)使用 Nimbus 外观和感觉的可用。我的问题是我无
我正在尝试全局更改工具提示的大小。 我正在使用: UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25)); 总体来说效果很
我们正在使用 Nimbus LaF 开发一个 Swing 应用程序。我们更改了许多 Nimbus 默认设置(控件、文本、NimbusLightBackground 等)以拥有深色主题。 现在我们在渲染
我想验证表格单元格中的用户输入,并且我使用了 Nimbus 外观。这是验证整数输入的单元格编辑器的代码:WholeNumberField它扩展了 JTextField 并添加了输入验证。 当我为列设置
我想知道为什么 Nimbus会以某种方式与 Virtual keys 发生冲突.查看我在下面制作的示例: public class buttontest implements ActionLi
只是寻找一些文档。 最佳答案 Nimbus 基于 Synth,因此您应该从 Synth 的角度考虑对其进行自定义,这一点已有详细记录。 关于java - 有人有关于 Nimbus 外观和感觉定制的信息
我想更改选项卡选项卡的高度,为此我尝试了多种方法,但没有成功。首先,我尝试使用间隔图标,高度很好,但选项卡的文本不再居中。然后我尝试更改 Nimbus L&F 属性,TabbedPane.tabIns
我有例如 UIDefaults defaults = UIManager.getLookAndFeelDefaults(); defaults.put("text",Color.GREEN);` 文本
我是一名优秀的程序员,十分优秀!