Browse Source

Fixed FileChooser filter popup hard to read.

pull/97/head
weisj 5 years ago
parent
commit
055955e359
  1. 8
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java
  2. 2
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java
  3. 44
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilterComboBoxRenderer.java
  4. 2
      core/src/test/java/ui/fileChooser/FileChooserDemo.java

8
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<Object> createFilterComboBoxRenderer() {
return new DarkFilterComboBoxRenderer();
}
protected static class DarkButtonAreaLayout extends ButtonAreaLayout {
protected DarkButtonAreaLayout() {

2
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<Object> createFilterComboBoxRenderer() {
return new FilterComboBoxRenderer();
}

44
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);
}
}

2
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);
});

Loading…
Cancel
Save