diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java index 2cc71a0b..47aea567 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java @@ -289,8 +289,7 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { filterComboBox.setEnabled(filterComboBox.getItemCount() > 1); } }); - filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, - filesOfTypeLabelText); + filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, filesOfTypeLabelText); filesOfTypeLabel.setLabelFor(filterComboBox); filterComboBox.setRenderer(createFilterComboBoxRenderer()); filesOfTypePanel.add(filterComboBox); @@ -318,6 +317,11 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { groupLabels(new AlignedLabel[]{fileNameLabel, filesOfTypeLabel}); } + @Override + protected ListCellRenderer createFilterComboBoxRenderer() { + return new DarkFilterComboBoxRenderer(); + } + protected static class DarkButtonAreaLayout extends ButtonAreaLayout { protected DarkButtonAreaLayout() { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java index 06afc195..aa36b132 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java @@ -785,7 +785,7 @@ public class DarkFileChooserUIBridge extends BasicFileChooserUI { * * @return a {@code Renderer} for types {@code ComboBox} */ - protected FilterComboBoxRenderer createFilterComboBoxRenderer() { + protected ListCellRenderer createFilterComboBoxRenderer() { return new FilterComboBoxRenderer(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilterComboBoxRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilterComboBoxRenderer.java new file mode 100644 index 00000000..a194a5b4 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilterComboBoxRenderer.java @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (c) 2020 Jannis Weis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.github.weisj.darklaf.ui.filechooser; + +import com.github.weisj.darklaf.ui.list.DarkListCellRenderer; + +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.awt.*; + +public class DarkFilterComboBoxRenderer extends DarkListCellRenderer { + + public Component getListCellRendererComponent(final JList list, + final Object value, final int index, final boolean isSelected, + final boolean cellHasFocus) { + + Object val = value; + if (value instanceof FileFilter) { + val = ((FileFilter) value).getDescription(); + } + return super.getListCellRendererComponent(list, val, index, isSelected, cellHasFocus); + } +} diff --git a/core/src/test/java/ui/fileChooser/FileChooserDemo.java b/core/src/test/java/ui/fileChooser/FileChooserDemo.java index b5adde2b..ac0ad1cc 100644 --- a/core/src/test/java/ui/fileChooser/FileChooserDemo.java +++ b/core/src/test/java/ui/fileChooser/FileChooserDemo.java @@ -26,6 +26,7 @@ package ui.fileChooser; import com.github.weisj.darklaf.LafManager; import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; public final class FileChooserDemo { @@ -33,6 +34,7 @@ public final class FileChooserDemo { SwingUtilities.invokeLater(() -> { LafManager.install(); JFileChooser chooser = new JFileChooser(System.getProperty("user.home")); + chooser.addChoosableFileFilter(new FileNameExtensionFilter("Test Filter", ".svg")); chooser.setMultiSelectionEnabled(true); chooser.showOpenDialog(null); });