如何改变JFrame中标题栏的颜色?
我正在使用以下代码
UIManager.put("JFrame.activeTitleBackground", Color.red);
来更改 JFrame 中的工具栏颜色。但这没有用。
是否可以更改 JFrame 中标题栏的颜色?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是不可能的。顶层 JFrame 由外观和样式控制。底层操作系统的感觉。
您可以更改
InternalFrame
的颜色。Its not possible. The top level JFrame is controlled by the look & feel of the underlying OS.
You CAN change the color of an
InternalFrame
.对于Windows10,在你的main方法中,你可以使用:
For Windows10, in your main method, you can use:
是的,我找到了解决方案。我认为这对于现在看到这个的人可能会有所帮助。
使用
FlatLaf
因为有很多外观和感觉。您可以在此处查看它们。
要更改标题栏背景颜色和前景色,请使用以下命令:-
现在我可以实现此目的:-
Yes I found the solution. I think it may be helpful for people who are seeing this now.
Use
FlatLaf
In that there are many look and feels. You can see them here.
To change the title bar background color and foreground color use this:-
Now I can achieve this:-
我知道我有点晚了,但这可能对其他人有帮助:
我搜索了整个互联网,找到了更改我的基于摇摆的应用程序的整个主题的方法。然后我找到了一篇关于这样做的文章:
有人可能会说:
如果您想访问标题栏,首先您应该有权访问本机 java 引擎库。幸运的是,有一种方法可以做到这一点:
第一步:JNA 使 Java 程序可以轻松访问本机共享库,而无需编写 Java 代码之外的任何内容。
因此,您可以使用此存储库来访问它们:JNA。
根据您使用的平台,某些元素可能会有所延迟。因此,请确保使用
jna-platform-5.8.0.jar
使您的应用与任何平台兼容。第二步:如果您不知道如何使用 JNA 库,那么您可以以此为例:示例
无论如何,这可以解决您有关标题栏颜色的问题;)
主要文章:外部链接
告诉我我的错误,帮助我提高英语写作水平:D
I know I'm a bit late, but this may help others:
I searched the whole internet to find the way to change the entire theme of my swing-based app. then I found an article about doing so:
Somebody may say:
If you want to access the title bar, first, you should have the access to the native java engine libraries. Fortunately, there is a way to it:
First Step: JNA provides Java programs easy access to native shared libraries without writing anything but Java code.
So you can use this repository to access to them: JNA.
Some elements may defer based on your platform you are using. So make sure you use
jna-platform-5.8.0.jar
to make your app compatible to any platforms.Second Step: If you don't know how to use JNA libraries, then you could use this as an example: example
anyway, this could solve your problem about title bar color ;)
Main Article: External Link
Help me improve my writing in English by telling me my mistakes :D
我认为目标是在Win10上实现真正的应用程序外观。由于无法真正更改窗口标题颜色,唯一的方法是自定义窗口。
虽然安装 Metal LAF 变体的示例提供了一个很好的例子,但我发现这个问题更加复杂。真正的Win10窗口必须有win10边框,透明边框(阴影),用户可以拖动以调整大小。标题必须使用Win10图标,并悬停为窗口按钮。
我会 f.setUndecorated(true);并自己绘制它,并设置窗口的插图,以便内容正常工作。
(小字:虽然我们都“知道”可以使用 LAF 自定义 Swing,但在现实生活中编写 LAF 总是比仅仅子类化和绘制自己的装饰要复杂得多。作为一种额外的麻烦,LAF 架构并不表达了所有的组件属性,而“原生”的LAF与原生的外观(例如查看win7下拉菜单)或感觉(下拉菜单不会滑出,win7下拉菜单没有悬停,但按钮有)相差甚远哦,更不用说缺乏类似Windows的组件,例如像样的Office 2016功能区,甚至是Win10的简单“切换”,真的,如果不酿造自己的组件,你就无法做太多事情。)
I think the goal is to achive a real application look on Win10. As it is not possible to change the window title color for real, the only way is to customize the window.
Although examples installing a variant of the Metal LAF gives a good example, I found that this problem is more complicated. A real Win10 window has to have win10 border, transparent border (shadow) where the user can drag for resize. The title has to use Win10 icons, and hovers for the window buttons.
I'd f.setUndecorated(true); and draw it on my own, and set the insets of the window so that the content will work as normal.
(Small print: although we all "know" that one can customize Swing with LAFs, in the real life writing a LAF is always a lot more complicated than just subclassing and drawing your own decoration. As an extra hassle, the LAF architecture does not express all the component properties, and the "native" LAF is quite far from the native look (e.g. check the win7 dropdown) or the feel (dropdowns don't slide out, win7 dropdowns have no hover, but buttons do). Oh, not to mention the lack of Windows-like components, such as a decent Office 2016 ribbon, or even a simple "toggle" of Win10. Really, you cannot do too much without brewing your own components.)