Skip to content

Commit

Permalink
FileChooser: use system icons (issue #100)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed May 15, 2020
1 parent b0c8f2c commit e75caf5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ FlatLaf Change Log
`flatlaf-swingx-<version>.jar`.
- CheckBox and RadioButton: Flag `opaque` is no longer ignored when checkbox or
radio button is used as table cell renderer. (issue #77)
- FileChooser: Use system icons. (issue #100)
- FileChooser: Fixed missing labels in file chooser when running on Java 9 or
later. (issue #98)
- PasswordField: Do not apply minimum width if `columns` property is greater
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package com.formdev.flatlaf.ui;

import java.awt.Dimension;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.metal.MetalFileChooserUI;
import com.formdev.flatlaf.util.UIScale;
Expand Down Expand Up @@ -117,6 +120,8 @@
public class FlatFileChooserUI
extends MetalFileChooserUI
{
private final FlatFileView fileView = new FlatFileView();

public static ComponentUI createUI( JComponent c ) {
return new FlatFileChooserUI( (JFileChooser) c );
}
Expand All @@ -134,4 +139,37 @@ public Dimension getPreferredSize( JComponent c ) {
public Dimension getMinimumSize( JComponent c ) {
return UIScale.scale( super.getMinimumSize( c ) );
}

@Override
public FileView getFileView( JFileChooser fc ) {
return fileView;
}

@Override
public void clearIconCache() {
fileView.clearIconCache();
}

//---- class FlatFileView -------------------------------------------------

private class FlatFileView
extends BasicFileView
{
@Override
public Icon getIcon( File f ) {
Icon icon = getCachedIcon( f );
if( icon != null )
return icon;

if( f != null ) {
icon = getFileChooser().getFileSystemView().getSystemIcon( f );
if( icon != null ) {
cacheIcon( f, icon );
return icon;
}
}

return super.getIcon( f );
}
}
}

0 comments on commit e75caf5

Please sign in to comment.