Skip to content

Commit 804d8b1

Browse files
committed
Fix grid colors on flatlaf l&f
1 parent e26e040 commit 804d8b1

File tree

8 files changed

+245
-201
lines changed

8 files changed

+245
-201
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Fixed
1414

1515
- Fix dead favicon supplier [#471](https://github.com/nbbrd/java-desktop-util/issues/471)
16+
- Fix grid colors on flatlaf l&f [#472](https://github.com/nbbrd/java-desktop-util/issues/472)
1617

1718
### Changed
1819

java-desktop-util-demo/src/main/java/ec/util/demo/JGridDemo.java

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,55 @@
11
/*
22
* Copyright 2013 National Bank of Belgium
3-
*
4-
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
3+
*
4+
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
55
* by the European Commission - subsequent versions of the EUPL (the "Licence");
66
* You may not use this work except in compliance with the Licence.
77
* You may obtain a copy of the Licence at:
8-
*
8+
*
99
* http://ec.europa.eu/idabc/eupl
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the Licence is distributed on an "AS IS" basis,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the Licence for the specific language governing permissions and
14+
* See the Licence for the specific language governing permissions and
1515
* limitations under the Licence.
1616
*/
1717
package ec.util.demo;
1818

19-
import ec.util.grid.CellIndex;
2019
import ec.util.chart.ObsIndex;
2120
import ec.util.chart.TimeSeriesChart;
2221
import ec.util.chart.swing.JTimeSeriesChart;
22+
import ec.util.demo.ext.JDemoPane;
23+
import ec.util.grid.CellIndex;
2324
import ec.util.grid.swing.AbstractGridModel;
2425
import ec.util.grid.swing.GridModel;
2526
import ec.util.grid.swing.GridModels;
2627
import ec.util.grid.swing.JGrid;
27-
import static ec.util.grid.swing.JGrid.COLUMN_SELECTION_ALLOWED_PROPERTY;
28-
import static ec.util.grid.swing.JGrid.DRAG_ENABLED_PROPERTY;
29-
import static ec.util.grid.swing.JGrid.MODEL_PROPERTY;
30-
import static ec.util.grid.swing.JGrid.ROW_SELECTION_ALLOWED_PROPERTY;
3128
import ec.util.various.swing.BasicSwingLauncher;
3229
import ec.util.various.swing.JCommand;
3330
import ec.util.various.swing.ModernUI;
34-
import java.awt.BorderLayout;
35-
import java.awt.Component;
36-
import java.awt.Dimension;
37-
import java.awt.Font;
38-
import java.beans.IntrospectionException;
39-
import java.beans.Introspector;
40-
import java.beans.PropertyChangeEvent;
41-
import java.beans.PropertyChangeListener;
42-
import java.beans.PropertyDescriptor;
31+
import lombok.NonNull;
32+
import org.jfree.data.time.*;
33+
import org.jfree.data.xy.IntervalXYDataset;
34+
35+
import javax.swing.*;
36+
import javax.swing.table.TableCellRenderer;
37+
import java.awt.*;
38+
import java.beans.*;
4339
import java.lang.reflect.InvocationTargetException;
4440
import java.text.*;
4541
import java.util.*;
46-
import javax.swing.Action;
47-
import javax.swing.JCheckBoxMenuItem;
48-
import javax.swing.JLabel;
49-
import javax.swing.JMenu;
50-
import javax.swing.JPanel;
51-
import javax.swing.JSplitPane;
52-
import javax.swing.JTable;
53-
import javax.swing.table.TableCellRenderer;
5442

55-
import lombok.NonNull;
56-
import org.jfree.data.time.Month;
57-
import org.jfree.data.time.TimePeriodAnchor;
58-
import org.jfree.data.time.TimeSeries;
59-
import org.jfree.data.time.TimeSeriesCollection;
60-
import org.jfree.data.time.TimeSeriesDataItem;
61-
import org.jfree.data.xy.IntervalXYDataset;
43+
import static ec.util.grid.swing.JGrid.*;
6244

6345
/**
64-
*
6546
* @author Philippe Charles
6647
*/
6748
public final class JGridDemo extends JPanel {
6849

6950
public static void main(String[] args) {
7051
new BasicSwingLauncher()
71-
.content(JGridDemo.class)
52+
.content(() -> JDemoPane.of(new JGridDemo()))
7253
.title("Grid Demo")
7354
.size(750, 300)
7455
.launch();

java-desktop-util-demo/src/main/java/ec/util/demo/MainDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static Component create() {
2828
result.add("JTimeSeriesChart", new JTimeSeriesChartDemo());
2929
result.add("JTimeSeriesRendererSupport", new JTimeSeriesRendererSupportDemo());
3030
result.add("SpinningIcon", new SpinningIconDemo());
31-
result.add("StandardSwingColor", StandardSwingColorDemo.create());
31+
result.add("StandardSwingColor", SwingColorDemo.create());
3232
result.add("ToolBarIcon", ToolBarIconDemo.create());
3333
result.add("XPopup", XPopupDemo.create());
3434
result.add("XTable", new XTableDemo());

java-desktop-util-demo/src/main/java/ec/util/demo/StandardSwingColorDemo.java renamed to java-desktop-util-demo/src/main/java/ec/util/demo/SwingColorDemo.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
/*
22
* Copyright 2015 National Bank of Belgium
3-
*
4-
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
3+
*
4+
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
55
* by the European Commission - subsequent versions of the EUPL (the "Licence");
66
* You may not use this work except in compliance with the Licence.
77
* You may obtain a copy of the Licence at:
8-
*
8+
*
99
* http://ec.europa.eu/idabc/eupl
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the Licence is distributed on an "AS IS" basis,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the Licence for the specific language governing permissions and
14+
* See the Licence for the specific language governing permissions and
1515
* limitations under the Licence.
1616
*/
1717
package ec.util.demo;
1818

19-
import internal.ColorIcon;
19+
import ec.util.demo.ext.JDemoPane;
2020
import ec.util.list.swing.JLists;
2121
import ec.util.various.swing.BasicSwingLauncher;
2222
import ec.util.various.swing.ModernUI;
2323
import ec.util.various.swing.StandardSwingColor;
2424
import ec.util.various.swing.UIItem;
25+
import internal.ColorIcon;
2526
import internal.Colors;
26-
import java.awt.Color;
27-
import java.awt.Component;
28-
import java.util.Arrays;
29-
import java.util.Comparator;
30-
import java.util.Locale;
31-
import javax.swing.JLabel;
32-
import javax.swing.JList;
33-
import javax.swing.JScrollPane;
27+
import internal.ExtSwingColor;
28+
29+
import javax.swing.*;
30+
import java.awt.*;
31+
import java.util.*;
32+
import java.util.List;
3433

3534
/**
36-
*
3735
* @author Philippe Charles
3836
*/
39-
public final class StandardSwingColorDemo {
37+
public final class SwingColorDemo {
4038

4139
public static void main(String[] args) {
4240
new BasicSwingLauncher()
43-
.content(StandardSwingColorDemo::create)
44-
.title("Standard Swing Colors")
45-
.size(300, 200)
41+
.content(() -> JDemoPane.of(create()))
42+
.title("Swing Colors")
43+
.size(400, 300)
4644
.launch();
4745
}
4846

49-
public static Component create() {
50-
StandardSwingColor[] values = StandardSwingColor.values();
51-
Arrays.sort(values, Comparator.comparing(UIItem::key));
47+
public static JComponent create() {
48+
List<UIItem<Color>> values = new ArrayList<>();
49+
Collections.addAll(values, StandardSwingColor.values());
50+
Collections.addAll(values, ExtSwingColor.values());
51+
values.sort(Comparator.comparing(UIItem::key));
5252

53-
JList<StandardSwingColor> list = new JList<>(values);
54-
list.setCellRenderer(JLists.cellRendererOf(StandardSwingColorDemo::applyColor));
53+
JList<UIItem<Color>> list = new JList<>();
54+
list.setModel(JLists.modelOf(values));
55+
list.setCellRenderer(JLists.cellRendererOf(SwingColorDemo::renderColor));
5556

5657
return ModernUI.withEmptyBorders(new JScrollPane(list));
5758
}
5859

59-
private static void applyColor(JLabel label, StandardSwingColor value) {
60+
private static void renderColor(JLabel label, UIItem<Color> value) {
6061
Color color = value.value();
6162
if (color != null) {
6263
label.setText(value.key() + " (" + Colors.toHex(color).toUpperCase(Locale.ROOT) + ")");
63-
label.setIcon(ColorIcon.of(color, label.getFont().getSize()));
6464
} else {
6565
label.setText(value.key() + " (null)");
66-
label.setIcon(null);
6766
}
67+
label.setIcon(ColorIcon.of(color, label.getFont().getSize()));
6868
}
6969
}

0 commit comments

Comments
 (0)