我怎样才能改变JFrame的标题栏的颜色?

我正在使用下面的代码,

UIManager.put("JFrame.activeTitleBackground", Color.red); 

用于更改JFrame中的工具栏颜色。 但它没有工作。

是否有可能改变JFrame的标题栏的颜色?

这是不可能的。 顶级JFrame由底层操作系统的外观和感觉控制。

您可以更改InternalFrame的颜色。

 //source : javax/swing/plaf/metal/MetalTitlePane.java import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.metal.*; public class TitleColor { public static void main_helper (String args[]) { JFrame f = new JFrame (); f.setDefaultCloseOperation ( JFrame.DISPOSE_ON_CLOSE ); f.setSize (300, 300); f.setLocationRelativeTo (null); f.setUndecorated ( true ); f.getRootPane ().setWindowDecorationStyle ( JRootPane.FRAME ); JPanel panel = new JPanel (); panel.setBackground ( java.awt.Color.white ); f.setContentPane ( panel ); DefaultMetalTheme z = new DefaultMetalTheme () { //inactive title color public ColorUIResource getWindowTitleInactiveBackground() { return new ColorUIResource (java.awt.Color.orange); } //active title color public ColorUIResource getWindowTitleBackground() { return new ColorUIResource (java.awt.Color.orange); } //start ActiveBumps public ColorUIResource getPrimaryControlHighlight() { return new ColorUIResource (java.awt.Color.orange); } public ColorUIResource getPrimaryControlDarkShadow() { return new ColorUIResource (java.awt.Color.orange); } public ColorUIResource getPrimaryControl() { return new ColorUIResource (java.awt.Color.orange); } //end ActiveBumps //start inActiveBumps public ColorUIResource getControlHighlight () { return new ColorUIResource (java.awt.Color.orange); } public ColorUIResource getControlDarkShadow () { return new ColorUIResource (java.awt.Color.orange); } public ColorUIResource getControl () { return new ColorUIResource (java.awt.Color.orange); } //end inActiveBumps }; MetalLookAndFeel.setCurrentTheme ( z ); try { UIManager.setLookAndFeel ( new MetalLookAndFeel () ); } catch (Exception e) { e.printStackTrace (); } SwingUtilities.updateComponentTreeUI (f); f.setVisible (true); } public static void main (final String args[]) { SwingUtilities.invokeLater ( new Runnable () { public void run () { main_helper ( args ); } } ); } } 
 UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(Color.black )); UIManager.put("InternalFrame.activeTitleForeground", new ColorUIResource(Color.WHITE)); UIManager.put("InternalFrame.titleFont", new Font("Dialog", Font.PLAIN, 11));