<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    I'm not sure wrapping it in a runLater would make much difference,
    and if it does, it would be fragile.<br>
    <br>
    I think that the best approach might be to disallow using the same
    Node as the "graphic" of two controls, in the same way that we
    disallow setting a Node as a clip of two different nodes. This would
    involve a CSR, since it's both a spec and a behavior change. The
    implementation would need to check whether the Node is in use, and
    if so, throw an exception (after first unbinding if bound).<br>
    <br>
    -- Kevin<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 12/1/2022 9:20 AM, Andy Goryachev
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:DM5PR1001MB2172E57ECE5C794C6A3A6DA4E5149@DM5PR1001MB2172.namprd10.prod.outlook.com">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
        {font-family:"Times New Roman \(Body CS\)";
        panose-1:2 11 6 4 2 2 2 2 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Courier New";
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}div.WordSection1
        {page:WordSection1;}</style>
      <div class="WordSection1">
        <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New"">Does
            wrapping the action code in runLater() help?</span><span style="font-size:11.0pt">
            <o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New"">b1.setOnAction((ev)
            -> {<o:p></o:p></span></p>
        <p class="MsoNormal" style="margin-left:13.5pt"><span style="font-size:11.0pt;font-family:"Courier New"">Platform.runLater(()
            -> {<br>
              if (b1.getParent() == cb1) {<o:p></o:p></span></p>
        <p class="MsoNormal" style="margin-left:13.5pt"><span style="font-size:11.0pt;font-family:"Courier New""> 
            ...<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt"><br>
          </span><span style="font-size:11.0pt;font-family:"Courier
            New"">-andy<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
        <div style="border:none;border-top:solid #B5C4DF
          1.0pt;padding:3.0pt 0in 0in 0in">
          <p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
              </span></b><span style="font-size:12.0pt;color:black">openjfx-dev
              <a class="moz-txt-link-rfc2396E" href="mailto:openjfx-dev-retn@openjdk.org"><openjfx-dev-retn@openjdk.org></a> on behalf of John
              Hendrikx <a class="moz-txt-link-rfc2396E" href="mailto:john.hendrikx@gmail.com"><john.hendrikx@gmail.com></a><br>
              <b>Date: </b>Thursday, 2022/12/01 at 09:14<br>
              <b>To: </b>Nir Lisker <a class="moz-txt-link-rfc2396E" href="mailto:nlisker@gmail.com"><nlisker@gmail.com></a><br>
              <b>Cc: </b><a class="moz-txt-link-abbreviated" href="mailto:openjfx-dev@openjdk.org">openjfx-dev@openjdk.org</a>
              <a class="moz-txt-link-rfc2396E" href="mailto:openjfx-dev@openjdk.org"><openjfx-dev@openjdk.org></a><br>
              <b>Subject: </b>Re: Setting graphics of a Labeled does
              not show the Label correctly<o:p></o:p></span></p>
        </div>
        <p>The mechanism does seem like it is a bit poorly designed, as
          it is easy to create inconsistencies.<o:p></o:p></p>
        <p>Luckily it seems that you can't remove a graphic yourself
          from a Control (getChildren is protected).<o:p></o:p></p>
        <p>I don't think there is an easy solution though...<o:p></o:p></p>
        <p>I think that once you set a graphic on a Labeled, you need to
          somehow mark it as "in use".  Normally you could just check
          parent != null for this, but it is trickier than that.  The
          Skin ultimately determines if it adds the graphic as child,
          which may be delayed or may even be disabled (content display
          property is set to showing TEXT only).<o:p></o:p></p>
        <p>Perhaps Skins should always add the graphic and just hide it
          (visible false, managed false), but that's going to be hard to
          enforce.<o:p></o:p></p>
        <p>Marking the graphic as "in use" could be done with:<o:p></o:p></p>
        <p>- a property in `getProperties`<br>
          - a new "owner" or "ownedBy" property<br>
          - allowing "parent" to be set without adding it to children
          (probably going to mess up stuff)<o:p></o:p></p>
        <p>--John<o:p></o:p></p>
        <div>
          <p class="MsoNormal"><span style="font-size:11.0pt">On
              01/12/2022 15:21, Nir Lisker wrote:<o:p></o:p></span></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <div>
            <p class="MsoNormal"><span style="font-size:11.0pt">Technically
                it doesn't appear elsewhere in the scenegraph, it is the
                child of only one label. It's set as the graphics
                property of 2 labels though. The mismatch is that being
                set as a graphics property isn't a 1-to-1 relationship
                with being a child of the label. <o:p></o:p></span></p>
            <div>
              <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
            </div>
            <div>
              <p class="MsoNormal"><span style="font-size:11.0pt">Something
                  has to be fixed along this chain of inconsistency, I
                  just wasn't sure where. It seems like the IAE that you
                  mentioned should be thrown, but isn't. I can write a
                  PR for that. One thing I'm not sure about is: in a
                  situation where the graphic belongs to a label that is
                  detached from a scene, and that graphic is set to a
                  label that *is* part of a scene, should an IAE be
                  thrown as well.<o:p></o:p></span></p>
            </div>
          </div>
        </blockquote>
        <p class="MsoNormal"><span style="font-size:11.0pt">Even if the
            Labeled is part of the Scene, the graphic may not be
            (depending on Skin used and on Content Display property for
            the default skin).<br>
            <br>
            <o:p></o:p></span></p>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <div>
            <div>
              <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
            </div>
            <div>
              <p class="MsoNormal"><span style="font-size:11.0pt">By the
                  way, changing to throwing an IAE is going to cause
                  some new exceptions. There is a possibility that some
                  VirtualFlow things will break because that mechanism
                  recycles nodes and re-attaches their properties. Then
                  again, it might just mean that it was done wrong.<o:p></o:p></span></p>
            </div>
          </div>
          <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
          <div>
            <div>
              <p class="MsoNormal"><span style="font-size:11.0pt">On
                  Thu, Dec 1, 2022 at 3:49 PM John Hendrikx <<a href="mailto:john.hendrikx@gmail.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">john.hendrikx@gmail.com</a>>
                  wrote:<o:p></o:p></span></p>
            </div>
            <blockquote style="border:none;border-left:solid #CCCCCC
              1.0pt;padding:0in 0in 0in
              6.0pt;margin-left:4.8pt;margin-right:0in">
              <div>
                <p>Sorry, I meant on the first click already.<o:p></o:p></p>
                <p>--John<o:p></o:p></p>
                <div>
                  <p class="MsoNormal"><span style="font-size:11.0pt">On
                      01/12/2022 14:46, John Hendrikx wrote:<o:p></o:p></span></p>
                </div>
                <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
                  <p>Setting the same Node for multiple graphics is not
                    allowed.  Your program should IMHO throw
                    "IllegalArgumentException" on the 2nd click.<o:p></o:p></p>
                  <p>     * An optional icon for the Labeled. This can
                    be positioned relative to the<br>
                         * text by using {@link #setContentDisplay}. 
                    The node specified for this<br>
                         * variable cannot appear elsewhere in the scene
                    graph, otherwise<br>
                         * the {@code IllegalArgumentException} is
                    thrown.  See the class<br>
                         * description of {@link Node} for more detail.<o:p></o:p></p>
                  <p>--John<o:p></o:p></p>
                  <div>
                    <p class="MsoNormal"><span style="font-size:11.0pt">On
                        01/12/2022 13:38, Nir Lisker wrote:<o:p></o:p></span></p>
                  </div>
                  <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
                    <div>
                      <p class="MsoNormal"><span style="font-size:11.0pt">That's my point.
                          Currently, a node can serve as the graphics
                          property for multiple Labels, but will appear
                          only in 1 because it can only have a single
                          parent in the scenegraph. While this is
                          technically fine, it causes issues like the
                          one I showed above. I'm not sure if a node is
                          supposed to be able to serve as multiple
                          graphics (and displayed only in the last Label
                          it was set to?), or removed from other Labels'
                          graphic properties just like is done for
                          children in the scenegraph. Personally, I find
                          it confusing that label.getGraphics() will
                          return a node that isn't shown in that label.<o:p></o:p></span></p>
                    </div>
                    <p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
                    <div>
                      <div>
                        <p class="MsoNormal"><span style="font-size:11.0pt">On Thu, Dec 1, 2022
                            at 2:21 PM John Hendrikx <<a href="mailto:john.hendrikx@gmail.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">john.hendrikx@gmail.com</a>>
                            wrote:<o:p></o:p></span></p>
                      </div>
                      <blockquote style="border:none;border-left:solid
                        #CCCCCC 1.0pt;padding:0in 0in 0in
                        6.0pt;margin-left:4.8pt;margin-right:0in">
                        <p class="MsoNormal"><span style="font-size:11.0pt">Internally the
                            graphics is just a child node, and nodes
                            can't be part of
                            <br>
                            the scene graph twice (this is done in
                            LabeledSkinBase).<br>
                            <br>
                            It showing up only once is probably because
                            it is getting removed from <br>
                            the other labels.<br>
                            <br>
                            I think things are probably getting out of
                            sync, where the graphics <br>
                            property may think it still has a certain
                            node as its graphics, but it <br>
                            is no longer a child of the label.<br>
                            <br>
                            --John<br>
                            <br>
                            On 01/12/2022 11:23, Nir Lisker wrote:<br>
                            > Hi,<br>
                            ><br>
                            > Given the following code<br>
                            ><br>
                            >         var cb1 = new Label("1");<br>
                            >         var cb2 = new Label  ("2");<br>
                            >         var b1 = new Button("A");<br>
                            >         cb1.setGraphic(b1);<br>
                            >         b1.setOnAction(e -> {<br>
                            >             if (b1.getParent() == cb1)
                            {<br>
                            >                 //
                            cb1.setGraphic(null);<br>
                            >                 cb2.setGraphic(b1);<br>
                            >             } else {<br>
                            >                 //
                            cb2.setGraphic(null);<br>
                            >                 cb1.setGraphic(b1);<br>
                            >             }<br>
                            >         });<br>
                            ><br>
                            > Pressing the first button will move it
                            (the graphic) to the second <br>
                            > label, however, pressing it again will
                            not move it back to the first <br>
                            > label. It's required to set the
                            graphics to null prior to moving them <br>
                            > as in the commented lines. This looks
                            like a bug to me. I would think <br>
                            > that when a graphic is moved, it will
                            appear in its new label <br>
                            > immediately, like moving a child.
                            Apparently a single node can be the <br>
                            > graphics for multiple Labeled nodes,
                            but it will appear only in 1. Is <br>
                            > this intentional?<br>
                            ><br>
                            > - Nir<o:p></o:p></span></p>
                      </blockquote>
                    </div>
                  </blockquote>
                </blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>