Skip to content

Commit dbc8366

Browse files
committed
HTML JLabels should inherit width and should wrap
1 parent 6b7e60b commit dbc8366

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public void setDraggable(JSFunction f) {
590590
/**
591591
* processed text (local to setIconAndText) is HTML
592592
*/
593-
private boolean isHTML;
593+
protected boolean isHTML;
594594

595595
/**
596596
* set false for tool tip or other non-label object that has text
@@ -1754,7 +1754,8 @@ protected Dimension setHTMLSize1(DOMNode node, boolean addCSS, boolean usePrefer
17541754
dim.height += h;
17551755
DOMNode.setStyles(node, "position", null);
17561756
if (w0 != null) {
1757-
DOMNode.setStyles(node, "width", w0, "height", h0);
1757+
DOMNode.setStyles(node, "width",
1758+
(isHTML && isLabel ? "inherit" : w0), "height", h0);
17581759
}
17591760
if (position != null) {
17601761
DOMNode.setStyles(node, "position", position);
@@ -2382,7 +2383,8 @@ protected void setIconAndText(String prop, Icon icon, int gap, String text) {
23822383
if (text == "\0") {
23832384
isPaintedOnly = true; // this cannot be undone
23842385
}
2385-
DOMNode.setStyles(textNode, "white-space", "nowrap");
2386+
if (!isHTML || !isLabel)
2387+
DOMNode.setStyles(textNode, "white-space", "nowrap");
23862388
if (icon == null) {
23872389
// tool tip does not allow text alignment
23882390
if (iconNode != null && allowTextAlignment
@@ -2648,11 +2650,10 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
26482650
Object cssTxt = getJSObject();
26492651
Object cssIcon = getJSObject();
26502652

2651-
addJSKeyVal(cssCtr, "position", "absolute", "top", null, "left", null, "transform", null, "width", wCtr + "px",
2653+
addJSKeyVal(cssCtr, "position", "absolute", "top", null, "left", null, "transform", null, "width", (isHTML && isLabel ? "inherit" : wCtr + "px"),
26522654
"height", hCtr + "px");
26532655
addJSKeyVal(cssIcon, "position", "absolute", "top", null, "left", null, "transform", null);
26542656
addJSKeyVal(cssTxt, "position", "absolute", "top", null, "left", null, "transform", null);
2655-
26562657
isFullyCentered = (alignHCenter && alignVCenter && wIcon == 0 || wText == 0 && margins.left == margins.right
26572658
&& margins.top == margins.bottom && myInsets.left == myInsets.right && myInsets.top == myInsets.bottom);
26582659
if (isFullyCentered) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public void paint(Graphics g, JComponent c) {
8484
DOMNode.setStyles(centeringNode, "visibility", "visible");
8585
super.paint(g, c);
8686
// TODO: implement this for buttons?
87-
DOMNode.setStyles(textNode, "overflow", "hidden", "white-space", "nowrap");
87+
if (isHTML)
88+
DOMNode.setStyles(textNode, "overflow", null, "white-space", null);
89+
else
90+
DOMNode.setStyles(textNode, "overflow", "hidden", "white-space", "nowrap");
8891
if (icon != null) {
8992
// The graphics object is translated to the label,
9093
// not the image, at this point. In order to get
@@ -110,6 +113,8 @@ public void paint(Graphics g, JComponent c) {
110113
@Override
111114
public Dimension getPreferredSize(JComponent jc) {
112115
updateDOMNode();
116+
if (isHTML)
117+
return null;
113118
return (isAWT ? getMinimumSizePeer(jc, label)
114119
: label == null ? super.getPreferredSize(jc)
115120
: JSGraphicsUtils.getPreferredButtonSize(((AbstractButton) jc),

0 commit comments

Comments
 (0)