首页 > 解决方案 > Swing JFrame.setDefaultLookAndFeelDecorated vs UIManager.setLookAndFeel

问题描述

In Swing, it appears there are two ways of setting the theme/look-and-feel of the application:

I'm wondering what the difference is between these is and when/why to use either of them.

标签: javaswinguser-interfacetheming

解决方案


Only the UIManager.setLookAndFeel(...) methods allow setting the look and feel of the application. This is the method you want to use to set a specific look and feel to your application.

Using the static JFrame.setDefaultLookAndFeelDecorated(...) will only affect how newly created JFrames will have their windows "decorated" (i.e. window title bar, close/minimize button etc). Either by the LookAndFeel or by the system (or the "window manager"). It does not affect the look and feel of the application in general.

From the docs:

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.

Personally, I rarely find good use for the latter method.


推荐阅读