Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8278904

Cell: misleading doc of updateItem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P5
    • tbd
    • jfx11, 8, jfx17
    • javafx

    Description

      A certain misunderstanding bubbled up in a recent QA at Stackoverflow: https://stackoverflow.com/a/70371971/203657

      The doc states that both text and graphic have to be nulled for empty cells. That's not quite correct: if we don't touch graphic in the not-empty block, there is no reason to null it in the empty block.

      Current code example:

      @Override protected void updateItem(T item, boolean empty) {
          super.updateItem(item, empty);

          if (empty || item == null) {
              setText(null);
              setGraphic(null);
          } else {
              setText(item.toString());
          }
      }

      Current text:

      We test for the empty condition, and if true, we set the text and graphic properties to null. If we do not do this, it is almost guaranteed that end users will see graphical artifacts in cells unexpectedly.

      Introduced in JDK-8095003.

      The text should emphasize that the not-/empty blocks need to be symmetric, something like:

      .. if true, we have to reset (to null or a reasonable default) every property that has been set in the not empty case ..

      The code example could then either set the graphic along with the text or not null it:

         super.updateItem(item, empty);

          if (empty || item == null) {
              setText(null);
          } else {
              setText(item.toString());
          }

      or:

         super.updateItem(item, empty);

          if (empty || item == null) {
              setText(null);
              setGraphic(null);
          } else {
              setText(item.toString());
              setGraphic(myGraphic)
          }


      Attachments

        Issue Links

          Activity

            People

              kpk Karthik P K
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: