2020-05-18 18:14:46
浏览数 (1)
在build.gradle中添加如下依赖,ikonli=11.5.0:
代码语言:javascript
复制implementation("org.kordamp.ikonli:ikonli-javafx:$ikonli")
implementation("org.kordamp.ikonli:ikonli-typicons-pack:$ikonli")
implementation("org.kordamp.ikonli:ikonli-material-pack:$ikonli")
implementation("org.kordamp.ikonli:ikonli-runestroicons-pack:$ikonli")
implementation("org.kordamp.ikonli:ikonli-icomoon-pack:$ikonli")
implementation("org.kordamp.ikonli:ikonli-fontawesome-pack:$ikonli")
implementation("org.kordamp.ikonli:ikonli-fontawesome5-pack:$ikonli")
View文件:
代码语言:javascript
复制class MainAPP : App(MainView::class)
class MainView : View("ikonli viewer:可直接在图标上点击右键->复制") {
lateinit var _tabpane: TabPane
lateinit var searchContainer: FlowPane
private val iconType = stringProperty("")
private val searchKey = stringProperty("")
private val ikonli = stringProperty()
private val ikonliNum = intProperty()
private val ikons = observableListOf<Ikon>()
val iconTypes = observableListOf(
"Material", "Runestroicons", "Icomoon", "Typicons"
, "FontAwesome", "FontAwesomeBrands", "FontAwesomeRegular", "FontAwesomeSolid"
)
override val root = borderpane {
left = vbox {
}
center = tabpane {
_tabpane = this
tabClosingPolicy = TabPane.TabClosingPolicy.UNAVAILABLE
selectionModel.selectedItemProperty().onChange {
it?.let {
if (it.text != "Search Result")
_iconNum(it.text)
else {
ikonliNum.set(searchContainer.children.size)
}
}
}
iconTypes.forEach {
tab(it) {
scrollpane {
flowpane {
_tabs(it, this)
prefWrapLengthProperty().bind((this@scrollpane).prefWidthProperty())
vgap = 5.0
hgap = 5.0
contextmenu {
item("copy") {
action {
clipboard.putString(ikonli.value)
}
}
}
}
prefWidth = 800.0
style {
borderColor = box(Color.RED)
}
}
}
}
tab("Search Result") {
scrollpane {
searchContainer = flowpane {
prefWrapLengthProperty().bind((this@scrollpane).prefWidthProperty())
vgap = 5.0
hgap = 5.0
}
prefWidth = 800.0
style {
borderColor = box(Color.RED)
}
}
}
}
top = hbox(5) {
alignment = Pos.CENTER
textfield(searchKey) {
minWidth = 400.0
promptText = "search key word here then click the search button"
}
button {
isDefaultButton = true
icon(Material.SEARCH)
action {
search()
}
}
}
bottom = hbox(5) {
label(iconType)
separator(Orientation.VERTICAL)
label(ikonliNum)
separator(Orientation.VERTICAL)
textfield(ikonli) {
hgrow = Priority.ALWAYS
}
alignment = Pos.CENTER_LEFT
}
right = drawer {
item("用法") {
vbox(5) {
label("JDK14 with javafx:")
hyperlink("https://d2.injdk.cn/openjdk/liberica/14/full/bellsoft-jdk14.0.1 8-windows-amd64-full.zip")
textarea {
vgrow = Priority.ALWAYS
text = """
1.add below to gradle.properties file:
ikonli=11.5.0
2.add below to build.gradle file:
implementation("org.kordamp.ikonli:ikonli-javafx:${'$'}ikonli")
implementation("org.kordamp.ikonli:ikonli-typicons-pack:${'$'}ikonli")
implementation("org.kordamp.ikonli:ikonli-material-pack:${'$'}ikonli")
implementation("org.kordamp.ikonli:ikonli-runestroicons-pack:${'$'}ikonli")
implementation("org.kordamp.ikonli:ikonli-icomoon-pack:${'$'}ikonli")
implementation("org.kordamp.ikonli:ikonli-fontawesome-pack:${'$'}ikonli")
implementation("org.kordamp.ikonli:ikonli-fontawesome5-pack:${'$'}ikonli")
3.add button to your view:
button {
graphic = FontIcon.of(Material.SEARCH, 20, Color.RED)
action {
}
}
""".trimIndent()
}
}
}
}
setPrefSize(1024.0, 600.0)
style {
fontSize = 14.px
}
}