更改 JFileChooser 的外观

Changing the look and feel of the JFileChooser

我正在使用 net beans 窗体创建小程序。该小程序依赖于 JFileChooser。如果我将程序编写为应用程序而不是小程序,文件选择器看起来会有所不同。为什么相同的代码在编写为 applet 或应用程序时会产生不同外观的文件选择器?另外,如何更改小程序中文件选择器的外观,使其看起来像应用程序中的文件选择器?

应用程序文件选择器:

小程序文件选择器:

您可以使用UIManager.setLookAndFeel()

您应该可以这样做:

SwingUtilities.updateComponentTreeUI(JFileChooser);

当您调用 UIManager.setLookAndFeel(…) in your application, existing components are not automatically updated as there is no global registry of all existing component. Hence, these components will look different than the components created afterwards. You may invoke updateUI() on a component to update it to the current look and feel. There is also the utility method SwingUtilities.updateComponentTreeUI(…) 时,它将在整个组件树上递归调用 updateUI()

但一般来说,最好尽早设置所需的外观,最好是在创建任何组件之前,以避免更新现有组件的必要性。