Skip to content

Commit da4be39

Browse files
additional fixes and added support to CheckBoxMenuItem
1 parent ac9287f commit da4be39

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

lib/material-ui-swing.jar

1.46 KB
Binary file not shown.

src/MaterialUISwingDemo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public static void main (String[] args) {
3434
jRadioButtonMenuItem.setText("prova RadioButtonMenuItem");
3535
menu1.add(jRadioButtonMenuItem);
3636

37+
//TestCheckBoxMenuItem
38+
JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem();
39+
checkBoxMenuItem.setText("test");
40+
menu1.add(checkBoxMenuItem);
41+
3742
menu1.add (item1);
3843
menu2.add (item2);
3944

src/mdlaf/MaterialLookAndFeel.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mdlaf;
22

33
import mdlaf.components.button.MaterialButtonUI;
4+
import mdlaf.components.checkBoxMenuItem.MaterialCheckBoxMenuItemUI;
45
import mdlaf.components.checkbox.MaterialCheckBoxUI;
56
import mdlaf.components.combobox.MaterialComboBoxUI;
67
import mdlaf.components.label.MaterialLabelUI;
@@ -57,6 +58,11 @@ public class MaterialLookAndFeel extends MetalLookAndFeel {
5758
private static final String sliderUI = MaterialSliderUI.class.getCanonicalName ();
5859
private static final String progressBarUI = MaterialProgressBarUI.class.getCanonicalName();
5960
private static final String radioButtonMenuItemUI = MaterialRadioButtonMenuItemUI.class.getCanonicalName();
61+
private static final String checkBoxMenuItemUI = MaterialCheckBoxMenuItemUI.class.getCanonicalName();
62+
63+
public static String getCheckBoxMenuItemUI() {
64+
return checkBoxMenuItemUI;
65+
}
6066

6167
public static String getRadioButtonMenuItemUI() {
6268
return radioButtonMenuItemUI;
@@ -117,6 +123,7 @@ protected void initClassDefaults (UIDefaults table) {
117123
table.put ("SliderUI", sliderUI);
118124
table.put("ProgressBarUI", progressBarUI);
119125
table.put("RadioButtonMenuItemUI", radioButtonMenuItemUI);
126+
table.put("CheckBoxMenuItemUI", checkBoxMenuItemUI);
120127
}
121128

122129
@Override
@@ -268,9 +275,22 @@ protected void initComponentDefaults (UIDefaults table) {
268275
table.put ("Tree.openIcon", new ImageIcon (MaterialImages.DOWN_ARROW));
269276
table.put ("Tree.selectionBorderColor", null);
270277

278+
table.put ("RadioButtonMenuItem.foreground", Color.BLACK);
279+
table.put ("RadioButtonMenuItem.selectionForeground", Color.BLACK);
271280
//If it changes the background of the menuitem it must change this too, irrespective of its setting
272281
table.put("RadioButtonMenuItem.background", UIManager.getColor ("MenuItem.background"));
282+
table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200);
283+
table.put ("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5));
273284
table.put("RadioButtonMenuItem.checkIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF));
274285
table.put("RadioButtonMenuItem.selectedCheckIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON));
286+
287+
//If it changes the background of the menuitem it must change this too, irrespective of its setting
288+
table.put("CheckBoxMenuItem.background", UIManager.getColor ("MenuItem.background"));
289+
table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200);
290+
table.put ("CheckBoxMenuItem.foreground", Color.BLACK);
291+
table.put ("CheckBoxMenuItem.selectionForeground", Color.BLACK);
292+
table.put ("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5));
293+
table.put("CheckBoxMenuItem.checkIcon", new ImageIcon(MaterialImages.UNCHECKED_BOX));
294+
table.put("CheckBoxMenuItem.selectedCheckIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX));
275295
}
276296
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package mdlaf.components.checkBoxMenuItem;
2+
3+
import mdlaf.resources.MaterialDrawingUtils;
4+
import javax.swing.*;
5+
import javax.swing.plaf.ComponentUI;
6+
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
7+
import java.awt.*;
8+
9+
/**
10+
*
11+
* @author https://github.com/vincenzopalazzo
12+
*
13+
*/
14+
15+
public class MaterialCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
16+
17+
public static ComponentUI createUI(JComponent c){
18+
return new MaterialCheckBoxMenuItemUI();
19+
}
20+
21+
@Override
22+
public void installUI(JComponent c) {
23+
super.installUI(c);
24+
}
25+
26+
@Override
27+
public void paint(Graphics g, JComponent c) {
28+
super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c);
29+
}
30+
31+
32+
@Override
33+
protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
34+
JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c;
35+
if(checkBoxMenuItem.isSelected()){
36+
super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), checkBoxMenuItem, UIManager.getIcon("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap);
37+
return;
38+
}
39+
super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), checkBoxMenuItem, UIManager.getIcon("CheckBoxMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap);
40+
}
41+
}

src/mdlaf/components/radiobuttonmenuitem/MaterialRadioButtonMenuItemUI.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package mdlaf.components.radiobuttonmenuitem;
22

3-
import mdlaf.resources.MaterialBorders;
4-
import mdlaf.resources.MaterialColors;
53
import mdlaf.resources.MaterialDrawingUtils;
6-
import mdlaf.resources.MaterialImages;
74

85
import javax.swing.*;
96
import javax.swing.plaf.ComponentUI;
107
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
118
import java.awt.*;
129

10+
/**
11+
*
12+
* @author https://github.com/vincenzopalazzo
13+
*
14+
*/
15+
1316
public class MaterialRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI {
1417

1518
public static ComponentUI createUI(JComponent c){

0 commit comments

Comments
 (0)