Created
September 26, 2017 05:30
-
-
Save briangordon/1f9c65f1333fa3355fc41cc8aca78563 to your computer and use it in GitHub Desktop.
Repro case for https://bugs.openjdk.java.net/browse/JDK-8187912
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cellfactory | |
import javafx.application.Application | |
import javafx.collections.FXCollections | |
import javafx.scene.control.ListView | |
import javafx.scene.layout.StackPane | |
import javafx.scene.{Scene, control => jfxsc} | |
import javafx.stage.Stage | |
import javafx.util.Callback | |
class TestLauncher extends Application { | |
def start(stage: Stage): Unit = { | |
val javafxComboBox = new jfxsc.ComboBox[MyCustomClass]() | |
val cellFactoryCallback = new Callback[jfxsc.ListView[MyCustomClass], jfxsc.ListCell[MyCustomClass]] { | |
override def call(param: ListView[MyCustomClass]) = new jfxsc.ListCell[MyCustomClass] { | |
// Customize the appearance of the cell. | |
override def updateItem(item: MyCustomClass, empty: Boolean): Unit = { | |
super.updateItem(item, empty) | |
if (empty || item == null) { | |
setText(null) | |
setGraphic(null) | |
} else { | |
setText("Good toString") | |
} | |
} | |
} | |
} | |
javafxComboBox.setCellFactory(cellFactoryCallback) | |
javafxComboBox.getSelectionModel.selectFirst() | |
javafxComboBox.setItems(FXCollections.observableArrayList(MyCustomClass("blah"), MyCustomClass("blahhh"))) | |
val root = new StackPane() | |
root.getChildren.add(javafxComboBox) | |
stage.setScene(new Scene(root)) | |
stage.show() | |
} | |
} | |
object TestLauncher { | |
def main(args: Array[String]): Unit = { | |
Application.launch(classOf[TestLauncher]) | |
} | |
} | |
case class MyCustomClass(str: String) { | |
override def toString = "Bad toString" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment