-
Bug
-
Resolution: Fixed
-
P4
-
8u40
-
8u40b9
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();
}
}
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();
}
}