如何在JavaFX中设置警报对话框的字体?

时间:2018-12-09 14:52:45

标签: java javafx fonts tornadofx

我正在使用JavaFX构建应用程序。

我可以为场景设置字体。但是我无法为系统警报对话框设置字体。

我正在使用TornadoFX和kotlin。

那怎么实现呢?

我将javafx.scene.control.Alert#Alert(javafx.scene.control.Alert.AlertType,java.lang.String,javafx.scene.control.ButtonType ...)用于对话框。

代码如下:

import javafx.application.Application
import javafx.collections.ObservableList
import org.apache.commons.io.FilenameUtils
import tornadofx.*
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.streams.toList

class Music(artist: String, title: String, filename: String) {
    var artist: String by property(artist)
    var title: String by property(title)
    var filename: String by property(filename)

    override fun toString(): String {
        return "Music($artist:$title)"
    }
}

class MainView : View() {
    private val mainController: MainController by inject()
    private val musics = mainController.loadMusics()

    override val root = tableview(musics) {
        minWidth = 600.0
        minHeight = 400.0
        column("Artist", Music::artist) {
            maxWidth = 200.0
        }
        column("Title", Music::title)
        onUserSelect {
            information("Selected: $it")
        }
    }

    init {
        musics.addAll(mainController.loadMusics())
    }
}

class MainStylesheet : Stylesheet() {
    init {
        root {
            fontFamily = "Noto Sans CJK SC Medium"
            fontSize = 20.px
        }
    }
}

class MainController : Controller() {
    fun loadMusics(): ObservableList<Music> {
        val matcher = FileSystems.getDefault().getPathMatcher("glob:**.{wma,mp3}")
        return Files.walk(Paths.get("/mnt/d/music/test"))
                .filter { Files.isRegularFile(it) }
                .filter { matcher.matches(it) }
                .map {
                    val baseName = FilenameUtils.getBaseName(it.toString())
                    val parts = baseName.split("-", limit = 2)
                    Music(parts.first(), parts.last(), it.toString())
                }.toList().observable()
    }
}

class App : tornadofx.App(MainView::class, MainStylesheet::class)

fun main(args: Array<String>) {
    Application.launch(App::class.java, *args)
}

以下是捕获内容:

enter image description here

0 个答案:

没有答案