Home > Software engineering >  How to make button in ComboBox do something on click
How to make button in ComboBox do something on click

Time:12-16

    val bar = VBox()
    val list: ObservableList<Button> = FXCollections.observableArrayList()

    val button = Button("20")

    button.setOnAction {
        changeFont(textWindow, button.text.toInt())
        println("works")
    }

    list.add(button)

    val comboBox: ComboBox<*> = ComboBox<Button>(list)

the changeFont is what I would want to happen, but the print statement wont work either.

CodePudding user response:

If anyone else comes across this issue,

val bar = VBox()
val list: ObservableList<Int> = FXCollections.observableArrayList(1,2,3)
val comboBox: ComboBox<*> = ComboBox<Int>(list)

comboBox.setOnAction {
    changeFont(textWindow, comboBox.value())
    println("works")
}

this worked for me, thanks to @kleopatra for answering in the comments.

  • Related