Skip to content

Instantly share code, notes, and snippets.

@seraphy
Created March 29, 2019 04:50
Show Gist options
  • Select an option

  • Save seraphy/ddc7fd6feaa7d45046ef790913f02234 to your computer and use it in GitHub Desktop.

Select an option

Save seraphy/ddc7fd6feaa7d45046ef790913f02234 to your computer and use it in GitHub Desktop.
Java8のJavaFXのComboBoxでnullを要素にもつリストを選択するとIndexOutOfBoundsException例外が発生する例。(Java11のJavaFX11では修正されており、問題は発生しないことを確認。)
package jp.seraphyware.example.lava8learn.jfx;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
* Java8のJavaFXのComboBoxでnullを要素にもつリストを選択すると
* IndexOutOfBoundsException例外が発生する例。
* (Java11のJavaFX11では修正されており、問題は発生しないことを確認。)
*
* https://bugs.openjdk.java.net/browse/JDK-8134923
*/
public class JFX8NullComboItemExample extends Application {
private final ObservableList<String> items = FXCollections.observableArrayList();
@Override
public void start(Stage stg) throws Exception {
VBox box = new VBox();
ComboBox<String> combo = new ComboBox<>(items);
combo.setPrefWidth(400);
combo.setMaxWidth(Double.MAX_VALUE);
box.getChildren().add(combo);
stg.setScene(new Scene(box));
stg.show();
items.setAll(null, "a");
}
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment