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

JavaDocs example should say that PseudoClasses must be cleared in updateItem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u45
    • javafx

      The JavaDocs of Cell::updateItem(T, boolean) already explains that it is absolutely necessary to set text and graphic to null in case of empty cells. While this is correct, it is only half the rent: In case a re-used Cell instance has set PseudoClasses, an empty cell would still keep these. As the super::updateItem call does not clear those classes, it is up to the programmer of the sub class to clear all known pseudo classes in case of (empty || item == null), just as he has to clear text and graphic. If not doing so, unexpected rendering issues (like wrong background colours etc.) might occur. Unfotunately, the solution is not as trivial as clearing text and graphics:

        if (empty || item == null) {
          setText(null);
          setGraphic(null);

          // For ALL custom pseudo classes execute:
          pseudoClassStateChanged(MY_PSEUDO_CLASS, false);
        }

      The problem is that the programmer not necessarily knows all custom pseudo classes. For example, he does not know which pseudo classes JavaFX by intention needs to keep activated, or which pseudo classes some library might have set to a non-empty cell. This is a open design issue with JavaFX, and hopefully Oracle's design team knows a solution for this.

            Unassigned Unassigned
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: