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

scalafx.scene.control.ComboBox buttonCell doesn't use cellFactory's updateItem

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      It's common when creating a ComboBox of user-defined types to set a custom cellFactory which overrides the updateItem method of ListCell. This allows you to define custom logic for transforming objects of type T into the String representation which is displayed in the Cell.

      For example:

                  // Customize the appearance of the cell.
                  override def updateItem(item: MyType, empty: Boolean): Unit = {
                      super.updateItem(item, empty)

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

      However, when the ComboBox is initially rendered, the "button cell" that it draws to occupy the space of the control does not use the user-defined cellFactory. Indeed, from com\sun\javafx\scene\control\skin\ComboBoxListViewSkin.java:

              buttonCell = comboBox.getButtonCell() != null ?
                      comboBox.getButtonCell() : getDefaultCellFactory().call(listView);

      Instead of using getDefaultCellFactory, this code should call comboBox.getCellFactory() and use that to construct the button cell.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a ComboBox with a custom cellFactory which overrides updateItem.

      Render the ComboBox.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The custom-formatted item should appear in the button cell
      ACTUAL -
      The default-formatted item appears in the button cell

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Currently you can manually call ComboBox.setButtonCell with the output of your custom cellFactory.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: