System appearance and appearance on JFileChooser, but with the look of a halo

The appearance and appearance of windows on JFileChooser is much better than the appearance and looks like a halo.

So, I'm looking for a way to have the look of the system, but you have a theme for nimbus or others.

Is it possible? If so, how can this be done?

+8
java swing look-and-feel jfilechooser nimbus
source share
2 answers

Perhaps, although I do not know if this is recommended. I managed to get it to work by asking the view to update itself on all but the topmost JFileChooser component (as this will replace all chooser components on Nimbus that you don't need).

I would see this as a hack that may or may not work depending on the appearance of Windows. It relies on almost all of JFileChooser created by Swing components. If it has ever been modified to use more direct native rendering (i.e. Java asks Windows to draw a significant portion of the selection), it will not work. I don't know how well this trick will work with other components.

Anyway, this code seemed to work with JDK 7:

package test; import java.awt.Component; import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.UIManager; import javax.swing.plaf.nimbus.NimbusLookAndFeel; //Or use com.sun.... if you are using JDK < 7 public class LAFTester { public static void main(String... args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JFileChooser chooser = new JFileChooser(); chooser.updateUI(); //Create UI objects UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName()); //Now set look and feel //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); //works with metal as well refreshUI(chooser, false); chooser.showOpenDialog(null); } private static void refreshUI(JComponent c, boolean includeParent) { if (includeParent) c.updateUI(); for (int i = 0; i < c.getComponentCount(); i++) { Component child = c.getComponent(i); if (child instanceof JComponent) { refreshUI((JComponent)child, true); } } } } 
+5
source share

I assume that you are talking about the panel on the left side of the Windows file selection dialog that has Desktop , My Computer My Documents icons in it?

Well, I doubt it can be done because it is LAF. This was added to Windows LAF because that is what the Windows platform file looks like. This is not support in other LAFs.

+2
source share

All Articles