java - Swing JFrame.setDefaultLookAndFeelDecorated vs UIManager.setLookAndFeel
问题描述
In Swing, it appears there are two ways of setting the theme/look-and-feel of the application:
JFrame.setDefaultLookAndFeelDecorated
, andUIManager.setLookAndFeel
I'm wondering what the difference is between these is and when/why to use either of them.
解决方案
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 JFrame
s 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
istrue
, the currentLookAndFeel
supports providing window decorations, and the current window manager supports undecorated windows, then newly createdJFrames
will have their Window decorations provided by the currentLookAndFeel
. Otherwise, newly createdJFrames
will have their Window decorations provided by the current window manager.
Personally, I rarely find good use for the latter method.
推荐阅读
- jquery - 选择具有最大数字的元素
- twig - Craft 3 entry.author.getPhoto() 在模板上为空,用户在详细信息部分上传了一张照片,我如何让照片显示?
- ruby - badRequest:无效请求[0]:未设置请求。(谷歌::Apis::ClientError)
- javascript - React Jsx 和 JS 文件条件
- firebase - Flutter 和 Firebase:在小部件中显示来自 cloud_firestore 的存储信息
- xamarin - Xamarin Foms SqlCommand 错误 Tcp 提供程序 35
- typescript - How to specify the type inside object spread because it can't infer
- python - 如何将 celeba 数据集加载到 spyder
- javascript - 无法弄清楚如何在 Javascript 游戏中实现三击功能
- css - 将 div 限制为具有固定纵横比的容器宽度和高度