Skip to content

Commit 3c1d52d

Browse files
committed
JMenu fixes for JSmol modelkit menu with no text
1 parent 82df83d commit 3c1d52d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,16 @@ protected void updateIcon() {
14571457
// it has a getIcon() method. JavaScript will not care if
14581458
// it is really a JLabel or JOptionPane, which also have icons
14591459
ImageIcon icon = getOrCreateIcon(c, null);
1460-
if (icon == null ? currentIcon != null : !icon.equals(currentIcon))
1461-
setIconAndText("icon", icon, currentGap, currentText);
1460+
if (icon == currentIcon && icon != null) {
1461+
BufferedImage bi = (BufferedImage) currentIcon.getImage();
1462+
if (bi.秘getImageNode(BufferedImage.GET_IMAGE_ALLOW_NULL) == imageNode) {
1463+
return;
1464+
}
1465+
}
1466+
if (menuAnchorNode != null) {
1467+
DOMNode.setStyle(menuAnchorNode, "min-width", "20px");
1468+
}
1469+
setIconAndText("icon", icon, currentGap, currentText);
14621470
}
14631471
}
14641472

@@ -2563,6 +2571,7 @@ protected void setIconAndText(String prop, Icon icon, int gap, String text) {
25632571
h = 20;
25642572
}
25652573
DOMNode.setStyles(iconNode, "height", h + "px", "width", w + "px");
2574+
DOMNode.setStyles(imageNode, "height", h + "px", "width", w + "px");
25662575
if (!imagePersists)
25672576
DOMNode.setStyle(imageNode, "visibility", "hidden");
25682577
}
@@ -2878,7 +2887,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
28782887
isFullyCentered = (alignHCenter && alignVCenter && wIcon == 0 || wText == 0
28792888
&& (actionNode == null || this.cellComponent != null || isSimpleButton) && margins.left == margins.right
28802889
&& margins.top == margins.bottom && myInsets.left == myInsets.right && myInsets.top == myInsets.bottom);
2881-
if (isFullyCentered) {
2890+
if (isFullyCentered && !isMenuItem) {
28822891
// simple totally centered label or button
28832892
// can't have width or height here --- let the browser figure that out
28842893
fullyCenter(cssCtr, isSimpleButton || isLabel);
@@ -3040,7 +3049,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
30403049
addJSKeyVal(cssAction, "top", "65%", "transform", "translateY(-100%) scale(0.6)");
30413050
addJSKeyVal(cssIcon, "top", "50%", "transform", "translateY(-80%)");
30423051
} else {
3043-
addJSKeyVal(cssIcon, "top", "50%", "transform", "translateY(-80%) scale(0.6)");
3052+
addJSKeyVal(cssIcon, "top", "50%", "transform", "translateY(-80%)");
30443053
}
30453054
}
30463055

@@ -3084,7 +3093,7 @@ private void setMenuAnchorAndAccelerator(AbstractButton b, int wCtr, boolean ltr
30843093
"margin", "0px 5px", "transform", "translateY(15%)");
30853094
}
30863095
}
3087-
if (!isMenu || isMenuItem)
3096+
if (!isMenu || isMenuItem && currentText != null && currentText.length() > 0)
30883097
DOMNode.setStyle(menuAnchorNode, // "width", "90%",
30893098
"min-width", Math.max(75, (23 + 15 + wCtr + wAccel + margins.left + margins.right)) + "px"); // was
30903099
}

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSMenuUI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public DOMNode updateDOMNode() {
3939
domNode = createItem(isMenuBarMenu ? "_bar" : "_elem", null);
4040
bindJQueryEvents(domNode, "mouseenter mouseleave", SOME_MOUSE_EVENT);
4141
}
42+
imagePersists = true;
4243
allowTextAlignment = isMenuItem = !isMenuBarMenu;
4344
containerNode = (isMenuBarMenu ? null : domNode);
4445
addClass(domNode, isMenuBarMenu ? "j2s-menuBar-menu" : "j2s-popup-menu");

0 commit comments

Comments
 (0)