本文整理汇总了Scala中scalafx.scene.control.Button类的典型用法代码示例。如果您正苦于以下问题:Scala Button类的具体用法?Scala Button怎么用?Scala Button使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Button类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PackageActionButtons
//设置package包名称以及导入依赖的类
package mco.ui.desktop.components
import scalafx.Includes._
import scalafx.geometry.{Insets, Pos}
import scalafx.scene.control.Button
import scalafx.scene.layout.{HBox, Priority, Region}
import mco.{ContentKind, Package}
import mco.ui.desktop.UIComponent
import mco.ui.state.{InstallPackage, UIAction, UninstallPackage}
import fx.tools.cats._
import cats.syntax.functor._
object PackageActionButtons extends UIComponent[Option[Package], HBox] {
override def apply(state: ObservableValueM[Option[Package]], act: (UIAction) => Unit): HBox =
new HBox {
hgrow = Priority.Always
alignmentInParent = Pos.CenterRight
padding = Insets(10, 0, 10, 0)
spacing = 10
children = Seq(
new Region {
minWidth = 10
maxWidth = Double.MaxValue
hgrow = Priority.Always
},
new Button("View README") {
prefWidth = 125
disable <== state.map(!_.exists(_.contents.exists(_.kind == ContentKind.Doc)))
onMouseClicked = handle { sys.error("Readme not implemented") }
},
new Button {
prefWidth = 125
text <== state.map {
case Some(p) if p.isInstalled => "Uninstall"
case _ => "Install"
}
disable <== state.map(_.isEmpty)
onAction <== state.map {
_.fold(handle { })( x =>
handle { act(if (!x.isInstalled) InstallPackage(x) else UninstallPackage(x)) })
}
defaultButton = true
}
)
}
}
示例2: newName
//设置package包名称以及导入依赖的类
package net.mikolak.pomisos.crud
import java.util.function.Predicate
import org.controlsfx.validation.{Severity, ValidationResult, ValidationSupport, Validator}
import scalafx.beans.property.{ObjectProperty, ReadOnlyObjectProperty}
import scalafx.event.ActionEvent
import scalafx.scene.control.{Button, TextField}
import scalafxml.core.macros.sfxml
import scalafx.Includes._
import scalafx.beans.binding.Bindings
import net.mikolak.pomisos.utils.Implicits._
trait AddNew {
def newName: ObjectProperty[Option[String]]
}
@sfxml
class AddNewController(
val addNewArea: TextField,
val addNewButton: Button
) extends AddNew {
lazy val newName = ObjectProperty[Option[String]](None)
setUpValidation()
def addItem(event: ActionEvent): Unit = {
newName.value = Some(addNewArea.text.value.toString).filter(_.nonEmpty)
addNewArea.text.value = ""
}
private def setUpValidation() = {
val textEmpty = addNewArea.text.mapToBoolean(_.trim().isEmpty)
addNewButton.disable <== textEmpty
val createItemHandle = addNewArea.onAction.value
def textValidator =
Validator.createPredicateValidator(new Predicate[String] {
override def test(t: String) = !textEmpty.value
}, "Name must not be empty", Severity.WARNING)
val validationSupport = new ValidationSupport()
validationSupport.registerValidator(addNewArea, textValidator)
validationSupport.initInitialDecoration()
val validationResult: ReadOnlyObjectProperty[ValidationResult] = validationSupport.validationResultProperty()
addNewArea.onAction <== validationResult.mapNullable(vR => if (vR.exists(_.getWarnings.isEmpty)) createItemHandle else null)
}
}
示例3: Sidebar
//设置package包名称以及导入依赖的类
package org.narrativeandplay.hypedyn.uicomponents
import scalafx.Includes._
import scalafx.geometry.Orientation
import scalafx.scene.Group
import scalafx.scene.control.{Label, Button, ToolBar}
object Sidebar extends ToolBar {
orientation = Orientation.Vertical
class SidebarButton(labelText: String) extends Button {
private val buttonLabel = new Label(labelText) {
rotate = -90
}
def buttonText = buttonLabel.text
def buttonText_=(inText: String): Unit = {
buttonLabel.text = inText
}
graphic = new Group(buttonLabel)
}
private lazy val factsButton = new SidebarButton("Hide facts") {
onAction = { _ =>
if (CentrePane.FactsPane.isShown) {
CentrePane.hide(CentrePane.FactsPane)
buttonText = "Show facts"
}
else {
CentrePane.show(CentrePane.FactsPane)
buttonText = "Hide facts"
}
}
}
items += factsButton
}