Skip to content

Commit a55c07e

Browse files
hansonrhansonr
authored andcommitted
use of \u00A0 (no-break space) when calculating preferred size for label
also adds min width of 1px and height of current font
1 parent 6ffc4a4 commit a55c07e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/SwingUtilities.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,18 @@ private static String layoutCompoundLabelImpl(
10191019
if (ui.textNode == null) {
10201020
textR.width = fm.stringWidth(text);
10211021
textR.height = fm.getHeight();
1022+
} else if (text.length() == 0) {
1023+
textR.width = 1;
1024+
textR.height = fm.getHeight();
10221025
} else {
1026+
String t = text.replace(' ', '\u00A0'); // no-break space
1027+
if (t != text)
1028+
DOMNode.setAttr(ui.textNode, "innerHTML", t);
10231029
Dimension d = ui.getHTMLSize(ui.textNode);
1024-
textR.width = d.width;
1025-
textR.height = d.height;
1030+
if (t != text)
1031+
DOMNode.setAttr(ui.textNode, "innerHTML", text);
1032+
textR.width = (d.width == 0 ? 1 : d.width);
1033+
textR.height = (d.height == 0 ? fm.getHeight() : d.height);
10261034
}
10271035
// Take into account the left and right side bearings.
10281036
// This gives more space than it is actually needed,

0 commit comments

Comments
 (0)