Swing Nimbus L& F - 自定义JInternalFrame标题栏 [英] Swing Nimbus L&F - Customized JInternalFrame title bar
问题描述
您好,我正在制作基于JDesktopPane的应用程序,我想让它具有Windows 8 metro风格的UI感觉,我对项目转移到JavaFX太过分了,我知道它已经地铁的样式表,所以我想知道是否可以自定义Nimbus,以便我可以将标题栏更改为纯色。在此先感谢!
Hello, I'm making a JDesktopPane based application, and I want to make it have a Windows 8 metro style UI feel to it, I'm too far in to the project to switch over to JavaFX, which I know has stylesheets for metro, so I was wondering if it's possible to customize Nimbus so that I can change the title bars to be a solid color. Thanks in advance!
推荐答案
我解决了!这也不算太难,所以对于寻找同样事情的人来说,这是一个很好的解决方案,我找到了一个解决方案:
我查看了这个网站: http://www.jasperpotts.com/blog/2008/08/skinning-a -slider-with-nimbus / ,详细介绍了如何自定义nimbus滑块,然后,在查看了有关Nimbus值的Java文档后,我发现了一个名为
I solved it! and it's not too hard either, so to be nice to people searching for the same thing, this is a solution I found:
I looked at this site: http://www.jasperpotts.com/blog/2008/08/skinning-a-slider-with-nimbus/, which details how to customize a nimbus slider, then, after looking at Java's documents about Nimbus values, I found one called
InternalFrame[Enabled+WindowFocused].backgroundPainter
绘制标题栏和窗口边框+背景的画家是哪个,所以我从滑块文章中获取了代码,稍微修改了一下,这就是我得到的:
Which is the painter which draws the title bar, and window border + background, so I took the code from the slider article, and modified it slightly, and this is what I got:
UIManager.put("InternalFrame[Enabled+WindowFocused].backgroundPainter", new Painter<Object>() {
@Override
public void paint(Graphics2D g, Object c, int w, int h) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setStroke(new BasicStroke(2f));
g.setColor(Color.GRAY);
g.fillRoundRect(0, 0, w-1, h-1, 8, 8);
g.setColor(Color.WHITE);
g.drawRoundRect(0, 0, w-1, h-1, 8, 8);
}});
UIManager.put("InternalFrame[Enabled].backgroundPainter", new Painter<Object>() {
@Override
public void paint(Graphics2D g, Object c, int w, int h) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setStroke(new BasicStroke(2f));
g.setColor(Color.RED);
g.fillRoundRect(0, 0, w-1, h-1, 8, 8);
g.setColor(Color.WHITE);
g.drawRoundRect(0, 0, w-1, h-1, 8, 8);
}});
你需要做的就是将它粘贴到某个地方在您的代码中,您将得到以下结果:
http://imgur.com / XuDGiHB
这显然非常简单,但如果你花更多的时间,你可以制作一些令人惊叹的窗户!
All you need to do is paste this somewhere in your code, and you will get this result:
http://imgur.com/XuDGiHB
This is obviously very simple, but if you spend more time with it, you can make some amazing looking windows!
这篇关于Swing Nimbus L& F - 自定义JInternalFrame标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!