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

[ComboBox] ComboBox must respect converter always

    Details

      Description

      ComboBox must never hard-code the displayValue if it has a StringConverter - it must pass all values (including null, aka: empty selection) to the converter and display the value it receives.

      There's a bit lee-way, if it has both a converter and a prompt ... then probably the prompt should win as it is specialized for the empty-selection case.

          /**
           * Converter must be used always (if available)
           *
           * Run:
           * - expected: display value "none"
           * - actual: empty
           */
          public class ComboBoxStringConverter extends Application
          {
            public static void main(String[] args)
            {
              Application.launch(args);
            }
          
            @Override
            public void start(Stage stage) throws Exception
            {
              final ComboBox<Integer> cb = new ComboBox<Integer>();
              cb.getItems().setAll(1, 2, 3);
              StringConverter converter = new StringConverter() {
                  @Override public String toString(Object arg0) {
                      if (arg0 == null) return "none";
                      return "item " + arg0; }
                  @Override public Integer fromString(String arg0) { throw new UnsupportedOperationException(); }
              };
              cb.setConverter(converter);
              VBox c = new VBox(cb);
              stage.setScene(new Scene(c, 500, 400));
              stage.setTitle(System.getProperty("java.version"));
              stage.show();
            }
          }

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: