1
+ import mdlaf .MaterialLookAndFeel ;
2
+ import mdlaf .animation .MaterialUIMovement ;
3
+ import mdlaf .resources .MaterialColors ;
4
+
5
+ import javax .swing .JButton ;
6
+ import javax .swing .JComboBox ;
7
+ import javax .swing .JFrame ;
8
+ import javax .swing .JLabel ;
9
+ import javax .swing .JMenu ;
10
+ import javax .swing .JMenuBar ;
11
+ import javax .swing .JMenuItem ;
12
+ import javax .swing .JPanel ;
13
+ import javax .swing .JProgressBar ;
14
+ import javax .swing .JSlider ;
15
+ import javax .swing .JToolBar ;
16
+ import javax .swing .UIManager ;
17
+ import javax .swing .UnsupportedLookAndFeelException ;
18
+
19
+ import com .sun .xml .internal .ws .org .objectweb .asm .Label ;
20
+
21
+ import java .awt .BorderLayout ;
22
+ import java .awt .Dimension ;
23
+
24
+ public class MaterialUISwingDemo {
25
+
26
+ public static void main (String [] args ) {
27
+ try {
28
+ UIManager .setLookAndFeel (new MaterialLookAndFeel ());
29
+ }
30
+ catch (UnsupportedLookAndFeelException e ) {
31
+ e .printStackTrace ();
32
+ }
33
+
34
+ // basic instantiation of JFrame with various components, including a
35
+ // JMenuBar with some menus and items, as well as a button
36
+ JFrame frame = new JFrame ("Material Design UI for Swing by atharva washimkar" );
37
+ frame .setMinimumSize (new Dimension (600 , 400 ));
38
+
39
+ // configuring the JMenuBar as well as its menus and items
40
+ JMenuBar bar = new JMenuBar ();
41
+ JMenu menu1 = new JMenu ("Option 1 (Animated)" );
42
+ JMenu menu2 = new JMenu ("Option 2 (Not animated)" );
43
+
44
+ JMenuItem item1 = new JMenuItem ("Item 1 (Animated)" );
45
+ JMenuItem item2 = new JMenuItem ("Item 2 (Not animated)" );
46
+
47
+ menu1 .add (item1 );
48
+ menu2 .add (item2 );
49
+
50
+ bar .add (menu1 );
51
+ bar .add (menu2 );
52
+
53
+ // configuring a simple JButton
54
+ JButton button = new JButton ("PRESS ME" );
55
+ button .setMaximumSize (new Dimension (200 , 200 ));
56
+
57
+ JPanel content = new JPanel ();
58
+ content .add (button );
59
+
60
+ //configure JToolBar
61
+ JToolBar toolBar = new JToolBar ();
62
+ toolBar .setRollover (true );
63
+ JButton buttonOne = new JButton ("button" );
64
+ toolBar .add (buttonOne );
65
+ toolBar .addSeparator ();
66
+ toolBar .add (new JButton ("button 2" ));
67
+ toolBar .add (new JComboBox (new String []{"A" ,"B" ,"C" }));
68
+ content .add (toolBar );
69
+
70
+ //Setting comboBox only
71
+ JLabel labelCombo = new JLabel ();
72
+ labelCombo .setText ("Combo" );
73
+ JComboBox <String > comboTest = new JComboBox <String >();
74
+ comboTest .addItem ("Prova uno" );
75
+ comboTest .addItem ("Prova due" );
76
+ content .add (labelCombo );
77
+ content .add (comboTest );
78
+
79
+ //settin Slider
80
+ JSlider slider = new JSlider ();
81
+ JSlider sliderVertical = new JSlider (JSlider .VERTICAL );
82
+ content .add (slider );
83
+ content .add (sliderVertical );
84
+
85
+ //test Progressbar
86
+ JProgressBar progressBar = new JProgressBar ();
87
+ progressBar .setMaximum (5 );
88
+ progressBar .setValue (2 );
89
+ content .add (progressBar );
90
+
91
+ // add everything to the frame
92
+ frame .add (bar , BorderLayout .PAGE_START );
93
+ frame .add (content , BorderLayout .CENTER );
94
+
95
+ // start animating!
96
+ // here, 'gray' is the color that the JComponent will transition to when the user hovers over it
97
+ MaterialUIMovement .add (menu1 , MaterialColors .GRAY_200 );
98
+ MaterialUIMovement .add (item1 , MaterialColors .GRAY_200 );
99
+
100
+ // you can also pass in extra parameters indicating how many intermediate colors to display, as well as the "frame rate" of the animation
101
+ // there will be 5 intermediate colors displayed in the transition from the original components color to the new one specified
102
+ // the "frame rate" of the transition will be 1000 / 30, or 30 FPS
103
+ // the animation will take 5 * 1000 / 30 = 166.666... milliseconds to complete
104
+ MaterialUIMovement .add (button , MaterialColors .BLUE_400 , 5 , 1000 / 30 );
105
+
106
+ // make everything visible to the world
107
+ frame .pack ();
108
+ frame .setVisible (true );
109
+ }
110
+ }
0 commit comments