Browse Source

Added List demo.

Fixed wrong selection color in list when not focused.

Signed-off-by: weisj <weisj@arcor.de>
pull/27/head
weisj 5 years ago
parent
commit
fda84f5881
  1. 3
      src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java
  2. 10
      src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java
  3. 1
      src/main/resources/com/github/weisj/darklaf/properties/ui/list.properties
  4. 72
      src/test/java/demo/list/ListDemo.java
  5. 4
      src/test/java/demo/splitPane/SplitPaneDemo.java
  6. 1
      src/test/java/demo/tabFrame/TabFrameDemo.java

3
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;
}

10
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());

1
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

72
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<String> list = new JList<>(week);
@Override
public JComponent createComponent() {
String[] week = {"Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"};
JList<String> 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<String>() {{
Map<String, Integer> mapping = new HashMap<String, Integer>() {{
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<String>() {{
Map<String, Integer> mapping = new HashMap<String, Integer>() {{
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";
}
}

4
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<String>() {{
Map<String, Integer> mapping = new HashMap<String, Integer>() {{
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<String>() {{
addItem("default");
addItem("line");

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

Loading…
Cancel
Save