java 是否可以更改 JFrame 或 JInternalFrame 的标题栏颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2482969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
is it possible to change titlebar color of JFrame or JInternalFrame
提问by Arivu2020
I am trying to change title bar color.but it dosen't work
UIManager.put("JFrame.activeCaption", new javax.swing.plaf.ColorUIResource( Color.GREEN));
JFrame.setDefaultLookAndFeelDecorated(true);
我正在尝试更改标题栏颜色。但它不起作用
UIManager.put("JFrame.activeCaption", new javax.swing.plaf.ColorUIResource(Color.GREEN)); JFrame.setDefaultLookAndFeelDecorated(true);
回答by Joe Carnahan
I do not think that you can do anything about the colors in the title bar of a JFrame, at least not without using native code to implement a platform-specific solution. That is because JFrameactually uses your native windowing system to create the window.
我不认为你可以对 a 标题栏中的颜色做任何事情JFrame,至少在不使用本机代码来实现特定于平台的解决方案的情况下不能。那是因为JFrame实际上使用您的本机窗口系统来创建窗口。
As for internal frames, it would make sense for you to be able to customize it, since it is a component rendered inside of a window that is controlled by Java. Indeed, there are plenty of JInternalFrameproperties that you can set in your UI manager. However, I wasn't able to get those to work on my system.
至于内部框架,您可以自定义它是有意义的,因为它是在由 Java 控制的窗口内呈现的组件。实际上,JInternalFrame您可以在 UI 管理器中设置许多属性。但是,我无法让它们在我的系统上运行。
Doing a little googling, it appears that others have found that you cannot change the appearance of JInternalFramewithout changing your whole system's look and feel settings.So, I'm afraid that you might have to depend on the operating system to control the colors of your title bars even when using internal frames.
稍微搜索一下,其他人似乎发现如果不更改JInternalFrame整个系统的外观和感觉设置,就无法更改外观。因此,恐怕您可能不得不依赖操作系统来控制标题栏的颜色,即使使用内部框架也是如此。
回答by Wintermut3
OK I think Joesaid it best, but remember you can decide not to decorate the Frame and then within the frame provide the ability to decorate it yourself. I have a Skin like set of custom AWT containers that do just that. The result is a GUI that looks or behaves nothing like what a Typical frame does--not "Rectangular" or "Square" "real estate" but something more like the Skins of applications like Winamp that cause the shape of the GUI to be asymmetric in design and look by by using the Alpha level in the OS GUI layer. In my Skin-able containers the "Skin" is an Image that is "cookie cut" up of a single image and then based on the geometry of Skin class draw and maintain those described areas--I only mention this as a way to literally "think outside of the box" of the type of problem.
好的,我认为Joe说得最好,但请记住,您可以决定不装饰框架,然后在框架内提供自己装饰它的能力。我有一套类似 Skin 的自定义 AWT 容器,可以做到这一点。结果是 GUI 的外观或行为与典型框架完全不同——不是“矩形”或“方形”“房地产”,而是更像 Winamp 等应用程序的皮肤,导致 GUI 的形状不对称在设计和外观中使用 OS GUI 层中的 Alpha 级别。在我的 Skin-able 容器中,“Skin”是一个图像,它是由单个图像“饼干切”出来的,然后基于 Skin 类的几何图形绘制并维护那些描述的区域——我只是提到这是一种从字面上看的方法”
WM
西马

