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

ChoiceBox does not display a selected item value which is not in the items list

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: openjfx11
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:

      Description

      ChoiceBox docs state "it is possible for the developer to specify the selected item to be something other than what is available in the predefined list".

      Example code:

      public class ChoiceTest extends Application {

          @Override
          public void start(Stage stage) throws Exception {
              ObservableList<String> list = FXCollections.observableArrayList("A", "B", "C");
              ChoiceBox<String> choiceBox = new ChoiceBox<>();
              choiceBox.getSelectionModel().select("D"); // or choiceBox.setValue
              choiceBox.setItems(list);

              stage.setScene(new Scene(choiceBox));
              stage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      The result is that the displayed item is blank. A quick look shows that ChoiceBoxSkin is set to display "" when selectedIndex = -1, which is the value for a selected item which is not in the list of items.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aghaisas Ajit Ghaisas
                Reporter:
                nlisker Nir Lisker
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: