如何在tornadofx中使模态最大化?

时间:2017-10-27 09:26:17

标签: javafx tornadofx

我需要打开最大化的模态。 我试过了

class BookingDetailView : Fragment("Booking Details") {
    override val root: BorderPane by fxml()
    init {
        modalStage?.isMaximized = true
    } 
}

编辑: 试图覆盖onDock()

class BookingDetailView : Fragment("Booking Details") {
override val root: BorderPane by fxml()
override fun onDock() {
//modalStage is null here. when i tried to debug . 
    **modalStage?.isMaximized = true**

}

}

从此视图调用:

class FindRoomView : View("Find Room") {
override val root: BorderPane by fxml()
private val dpArrivalDate: JFXDatePicker  by fxid()
private val tparrivalTime: JFXTimePicker by fxid()
private val dpDepartureDate: JFXDatePicker by fxid()
private val dpDepartureTime: JFXTimePicker by fxid()
private val btnFindRoom: JFXButton by fxid()
private val cbAdult: JFXComboBox<*> by fxid()
private val cbChildren: JFXComboBox<*> by fxid()
private val btnClear: JFXButton by fxid()
private val btnAdvanceBooking: JFXButton by fxid()
private val btnBookNow: JFXButton by fxid()
val count = FXCollections.observableArrayList<Int>()
//  val selections = FXCollections.observableArrayList<AdvanceBookingRoomModel>()
val availability = listOf(RoomType("AC"), RoomType("Non-AC")).observable()

init {
    //    model.item = this
    // model.count.value +=1..50
    //   (1..50).forEach { i -> model.count.value.add(i) }
    //    dpArrivalDate.bind(model.arrivalDateProperty)
    cbChildren.items = count
    cbAdult.items = count
    //   btnBookNow.setOnAction { bookNow() }
    btnBookNow.action { bookNow() }

}

private fun bookNow() {
    //  openInternalWindow(BookingDetailView::class,owner = root)
    find(BookingDetailView::class).openWindow()
}
}

它确实不起作用。 我还想在模态上使用最小化和最大化按钮。 怎么做? Output of Edvin's code

1 个答案:

答案 0 :(得分:1)

初始化Fragment时尚未创建modalStage,因此modalStage此时始终为null。改为覆盖onDock并在那里设置isMaximized = true

您可以将stageStyle参数传递给openModalopenWindow,以控制创建的窗口中的可用图标。以下是一个完整的应用程序,其中显示了如何访问modalStage中的onDock

class ModalApp : App(FindRoomView::class)

class FindRoomView : View("Find Room") {
    override val root = stackpane {
        button("Book now").action {
            find(BookingDetailView::class).openWindow()
        }
    }
}

class BookingDetailView : Fragment("Booking Details") {
    override val root = borderpane()

    override fun onDock() {
        modalStage?.isMaximized = true
        println(modalStage)
    }
}