摆动 JFrame.setDefaultLookAndFeelDecorated 对 UIManager.setLookAndFeel

Swing JFrame.setDefaultLookAndFeelDecorated vs UIManager.setLookAndFeel

在 Swing 中,似乎有两种设置应用程序 theme/look-and-feel 的方法:

我想知道它们之间的区别是什么 when/why 使用它们中的任何一个。

只有 UIManager.setLookAndFeel(...) 方法允许设置应用程序的外观。这是您要用来为您的应用程序设置特定外观的方法。

使用静态 JFrame.setDefaultLookAndFeelDecorated(...) 只会影响新创建的 JFrame 的 windows "decorated"(即 window 标题栏,close/minimize 按钮等)。通过 LookAndFeel 或系统(或 "window manager")。它一般不会影响应用程序的外观。

来自文档:

If defaultLookAndFeelDecorated is true, the current LookAndFeel supports providing window decorations, and the current window manager supports undecorated windows, then newly created JFrames will have their Window decorations provided by the current LookAndFeel. Otherwise, newly created JFrames will have their Window decorations provided by the current window manager.

就我个人而言,后一种方法很少有用。