1
+ package mdlaf .components .scrollbar ;
2
+
3
+ import mdlaf .resources .MaterialColors ;
4
+ import mdlaf .resources .MaterialDrawingUtils ;
5
+ import mdlaf .resources .MaterialFonts ;
6
+ import mdlaf .resources .MaterialImages ;
7
+
8
+ import javax .swing .BorderFactory ;
9
+ import javax .swing .ImageIcon ;
10
+ import javax .swing .JButton ;
11
+ import javax .swing .JComponent ;
12
+ import javax .swing .JScrollBar ;
13
+ import javax .swing .plaf .ComponentUI ;
14
+ import javax .swing .plaf .basic .BasicScrollBarUI ;
15
+ import java .awt .Graphics ;
16
+
17
+ /*
18
+ * Contributed by https://github.com/downToHell
19
+ * */
20
+
21
+ public class MaterialScrollBarUI extends BasicScrollBarUI {
22
+
23
+ private static boolean DEBUG = false ;
24
+
25
+ public static ComponentUI createUI (JComponent c ) {
26
+ return new MaterialScrollBarUI ();
27
+ }
28
+
29
+ @ Override
30
+ public void installUI (JComponent c ) {
31
+ super .installUI (c );
32
+
33
+ JScrollBar scrollBar = (JScrollBar ) c ;
34
+ scrollBar .setFont (MaterialFonts .REGULAR );
35
+ trackColor = MaterialColors .GRAY_200 ;
36
+ thumbColor = thumbDarkShadowColor = thumbHighlightColor = thumbLightShadowColor = MaterialColors .GRAY_300 ;
37
+ }
38
+
39
+ @ Override
40
+ public void paint (Graphics g , JComponent c ) {
41
+ super .paint (MaterialDrawingUtils .getAliasedGraphics (g ), c );
42
+ }
43
+
44
+ /**
45
+ * @author https://github.com/vincenzopalazzo
46
+ * The method takes an integer variable that for the createDecreaseButton
47
+ * method takes 7 if the scrollbar is horizontal and 1 if vertical
48
+ */
49
+ @ Override
50
+ protected JButton createDecreaseButton (int orientation ) {
51
+ JButton button = new JButton ();
52
+ if (DEBUG == true ) System .out .println ("orientation decrese: " + orientation );
53
+ if (orientation == 7 ) {
54
+ if (DEBUG == true ) System .out .println ("orientation decrese down: " + orientation );
55
+ button = new JButton (new ImageIcon (MaterialImages .LEFTH_ARROW ));
56
+ }else {
57
+ if (DEBUG == true ) System .out .println ("orientation decrese right: " + orientation );
58
+ button = new JButton (new ImageIcon (MaterialImages .UP_ARROW ));
59
+ }
60
+
61
+ button .setOpaque (true );
62
+ button .setBackground (MaterialColors .GRAY_300 );
63
+ button .setBorder (BorderFactory .createEmptyBorder ());
64
+
65
+ return button ;
66
+ }
67
+
68
+ /**
69
+ * @author https://github.com/vincenzopalazzo
70
+ * The method takes an integer variable that for the createIncreaseButton
71
+ * method takes 5 if the scrollbar is horizontal and 3 if vertical
72
+ */
73
+ @ Override
74
+ protected JButton createIncreaseButton (int orientation ) {
75
+ JButton button = new JButton ();
76
+ if (DEBUG == true ) System .out .println ("orientation increse: " + orientation );
77
+ if (orientation == 5 ) {
78
+ if (DEBUG == true ) System .out .println ("orientation decrese up: " + orientation );
79
+ button = new JButton (new ImageIcon (MaterialImages .DOWN_ARROW ));
80
+ }else {
81
+ if (DEBUG == true ) System .out .println ("orientation decrese lefth: " + orientation );
82
+ button = new JButton (new ImageIcon (MaterialImages .RIGHT_ARROW ));
83
+ }
84
+ button .setOpaque (true );
85
+ button .setBackground (MaterialColors .GRAY_300 );
86
+ button .setBorder (BorderFactory .createEmptyBorder ());
87
+
88
+ return button ;
89
+ }
90
+ }
0 commit comments