我需要打开最大化的模态。 我试过了
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()
}
}
答案 0 :(得分:1)
初始化Fragment时尚未创建modalStage
,因此modalStage
此时始终为null。改为覆盖onDock
并在那里设置isMaximized = true
。
您可以将stageStyle
参数传递给openModal
和openWindow
,以控制创建的窗口中的可用图标。以下是一个完整的应用程序,其中显示了如何访问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)
}
}