net.dankito.utils.javafx.ui.extensions.TableColumnBaseExtensions.kt Maven / Gradle / Ivy
package net.dankito.utils.javafx.ui.extensions
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue
import javafx.scene.control.TableColumnBase
import javafx.scene.control.TableView
fun TableColumnBase<*, *>.addStyleToCurrentStyle(styleToAdd: String) {
this.style = this.appendStyleToCurrentStyleString(styleToAdd)
}
fun TableColumnBase<*, *>.initiallyUseRemainingSpace(tableView: TableView<*>) {
val column = this
val tableWidthChangedListener = object : ChangeListener {
override fun changed(observable: ObservableValue, oldValue: Number, newValue: Number) {
if (newValue.toDouble() > 0.0) {
tableView.widthProperty().removeListener(this)
var otherColumnsWidth = 0.0
tableView.columns.forEach { tableColumn ->
if (tableColumn != column) {
otherColumnsWidth += tableColumn.width
}
}
column.prefWidth = tableView.width - otherColumnsWidth - 2.0
}
}
}
tableView.widthProperty().addListener(tableWidthChangedListener)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy