diff --git a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java index bacf2960..fe35f3d2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java +++ b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java @@ -75,10 +75,11 @@ public class DarkListCellRenderer extends DefaultListCellRenderer { } else { if (DarkUIUtil.hasFocus(list) || DarkUIUtil.getParentOfType(JPopupMenu.class, list) != null) { comp.setForeground(list.getSelectionForeground()); + comp.setBackground(list.getSelectionBackground()); } else { + comp.setBackground(UIManager.getColor("List.selectionNoFocusBackground")); comp.setForeground(UIManager.getColor("List.selectionForegroundInactive")); } - comp.setBackground(list.getSelectionBackground()); } return comp; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java index b3adb75d..679c25bd 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java @@ -31,6 +31,7 @@ import javax.swing.*; import javax.swing.plaf.ComponentUI; import java.awt.*; import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; /** * @author Jannis Weis @@ -184,6 +185,15 @@ public class DarkListUI extends DarkListUIBridge { protected class DarkHandler extends Handler { + @Override + public void propertyChange(final PropertyChangeEvent e) { + super.propertyChange(e); + String key = e.getPropertyName(); + if ("JList.alternateRowColor".equals(key)) { + list.repaint(); + } + } + @Override protected void adjustSelection(final MouseEvent e) { int row = list.locationToIndex(e.getPoint()); diff --git a/src/main/resources/com/github/weisj/darklaf/properties/ui/list.properties b/src/main/resources/com/github/weisj/darklaf/properties/ui/list.properties index c13bd02b..d1f81ef1 100644 --- a/src/main/resources/com/github/weisj/darklaf/properties/ui/list.properties +++ b/src/main/resources/com/github/weisj/darklaf/properties/ui/list.properties @@ -30,6 +30,7 @@ List.focusCellHighlightBorder = com.github.weisj.darklaf.ui.list.DarkLis List.cellNoFocusBorder = com.github.weisj.darklaf.ui.list.DarkListCellBorder List.dropLineColor = %dropForeground List.selectionBackground = %highlightFillFocus +List.selectionNoFocusBackground = %highlightFill List.focusBorderColor = %borderFocus List.alternateRowBackground = %backgroundAlternative List.selectionForegroundInactive = %textSelectionForegroundInactive diff --git a/src/test/java/demo/list/ListDemo.java b/src/test/java/demo/list/ListDemo.java index 08cb5186..2a25e6f2 100644 --- a/src/test/java/demo/list/ListDemo.java +++ b/src/test/java/demo/list/ListDemo.java @@ -23,28 +23,68 @@ */ package demo.list; -import com.github.weisj.darklaf.LafManager; +import demo.ComponentDemo; +import demo.DemoPanel; import javax.swing.*; +import java.awt.*; +import java.util.HashMap; +import java.util.Map; -public final class ListDemo { +public final class ListDemo implements ComponentDemo { public static void main(final String[] args) { - //Todo Rework Demo - SwingUtilities.invokeLater(() -> { - LafManager.install(); - JFrame f = new JFrame("frame"); - JPanel p = new JPanel(); + ComponentDemo.showDemo(new ListDemo()); + } - String[] week = {"Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday", "Sunday"}; - JList list = new JList<>(week); + @Override + public JComponent createComponent() { + String[] week = {"Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday", "Sunday"}; + JList list = new JList<>(week); + list.setSelectedIndex(2); + DemoPanel panel = new DemoPanel(list, new BorderLayout()); + JPanel controlPanel = panel.getControls(); + controlPanel.setLayout(new GridLayout(3, 2)); + controlPanel.add(new JLabel()); + controlPanel.add(new JCheckBox("JList.alternateRowColor") {{ + setSelected(Boolean.TRUE.equals(list.getClientProperty("JList.alternateRowColor"))); + addActionListener(e -> list.putClientProperty("JList.alternateRowColor", isSelected())); + }}); + controlPanel.add(new JLabel("Layout orientation:", JLabel.RIGHT)); + controlPanel.add(new JComboBox() {{ + Map mapping = new HashMap() {{ + put("VERTICAL", JList.VERTICAL); + put("VERTICAL_WRAP", JList.VERTICAL_WRAP); + put("HORIZONTAL_WRAP", JList.HORIZONTAL_WRAP); + }}; + addItem("VERTICAL"); + addItem("VERTICAL_WRAP"); + addItem("HORIZONTAL_WRAP"); + setSelectedItem("VERTICAL"); + //noinspection MagicConstant + addItemListener(e -> list.setLayoutOrientation(mapping.get(e.getItem().toString()))); + }}); + controlPanel.add(new JLabel("Selection mode:", JLabel.RIGHT)); + controlPanel.add(new JComboBox() {{ + Map mapping = new HashMap() {{ + put("SINGLE_SELECTION", ListSelectionModel.SINGLE_SELECTION); + put("MULTIPLE_INTERVAL_SELECTION", ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + put("SINGLE_INTERVAL_SELECTION", ListSelectionModel.SINGLE_INTERVAL_SELECTION); + }}; + addItem("SINGLE_SELECTION"); + addItem("MULTIPLE_INTERVAL_SELECTION"); + addItem("SINGLE_INTERVAL_SELECTION"); + setSelectedItem("SINGLE_SELECTION"); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + //noinspection MagicConstant + addItemListener(e -> list.setSelectionMode(mapping.get(e.getItem().toString()))); + }}); + return panel; + } - list.setSelectedIndex(2); - p.add(list); - f.add(p); - f.setSize(400, 400); - f.setVisible(true); - }); + @Override + public String getTitle() { + return "List Demo"; } } diff --git a/src/test/java/demo/splitPane/SplitPaneDemo.java b/src/test/java/demo/splitPane/SplitPaneDemo.java index 3d7ad7de..a6b17ed7 100644 --- a/src/test/java/demo/splitPane/SplitPaneDemo.java +++ b/src/test/java/demo/splitPane/SplitPaneDemo.java @@ -60,7 +60,7 @@ public final class SplitPaneDemo implements ComponentDemo { setSelected(splitPane.isOneTouchExpandable()); addActionListener(e -> splitPane.setOneTouchExpandable(isSelected())); }}); - controlPanel.add(new JLabel("Orientation:")); + controlPanel.add(new JLabel("Orientation:", JLabel.RIGHT)); controlPanel.add(new JComboBox() {{ Map mapping = new HashMap() {{ put("VERTICAL_SPLIT", JSplitPane.VERTICAL_SPLIT); @@ -72,7 +72,7 @@ public final class SplitPaneDemo implements ComponentDemo { //noinspection MagicConstant addItemListener(e -> splitPane.setOrientation(mapping.get(e.getItem().toString()))); }}); - controlPanel.add(new JLabel("JSplitPane.style:")); + controlPanel.add(new JLabel("JSplitPane.style:", JLabel.RIGHT)); controlPanel.add(new JComboBox() {{ addItem("default"); addItem("line"); diff --git a/src/test/java/demo/tabFrame/TabFrameDemo.java b/src/test/java/demo/tabFrame/TabFrameDemo.java index cb59a233..c846097d 100644 --- a/src/test/java/demo/tabFrame/TabFrameDemo.java +++ b/src/test/java/demo/tabFrame/TabFrameDemo.java @@ -42,7 +42,6 @@ import java.awt.*; public class TabFrameDemo implements ComponentDemo { public static void main(final String[] args) { - //Todo Rework Demo ComponentDemo.showDemo(new TabFrameDemo(), new Dimension(1000, 500)); }