Skip to content

Commit da5e964

Browse files
hansonrhansonr
authored andcommitted
Fix for occasional JLabel appearing on left of page
new JSLabelUI.paint(g,c) was not always removing the node from body after checking getBoundingClientRect()
1 parent 2f5750d commit da5e964

7 files changed

Lines changed: 14 additions & 4 deletions

File tree

614 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181217163947
1+
20181217180014
614 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181217163947
1+
20181217180014
614 Bytes
Binary file not shown.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,16 @@ private static String layoutCompoundLabelImpl(
10181018
textR.width = fm.stringWidth(text);
10191019
textR.height = fm.getHeight();
10201020
} else {
1021+
1022+
System.out.println("laying out " + /** @j2sNative document.body.children.length ||*/null);
1023+
System.out.println("laying out " + /** @j2sNative ui.text ||*/null);
1024+
1025+
10211026
Dimension d = ui.getHTMLSize(ui.textNode);
1027+
System.out.println("laying out done " + /** @j2sNative document.body.children.length ||*/null);
1028+
System.out.println("laying out done " + /** @j2sNative ui.text ||*/null);
1029+
1030+
10221031
textR.width = d.width;
10231032
textR.height = d.height;
10241033
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ public void paint(Graphics g, JComponent c) {
124124
DOMNode.setStyles(imageNode, "visibility", null);
125125
Rectangle r = imageNode.getBoundingClientRect();
126126
DOMNode parent = null;
127-
if (r.width == 0) {
127+
boolean isHidden = (r.width == 0);
128+
if (isHidden) {
128129
parent = DOMNode.getParent(domNode);
129130
$("body").append(domNode);
130131
r = imageNode.getBoundingClientRect();
131132
}
132133
Rectangle r0 = domNode.getBoundingClientRect();
133-
if (parent != null)
134+
if (isHidden)
134135
DOMNode.transferTo(domNode, parent);
135136
DOMNode.setStyles(imageNode, "visibility", "hidden");
136137
icon.paintIcon(c, g, (int) (r.x - r0.x), (int) (r.y - r0.y));

0 commit comments

Comments
 (0)