Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ScalaFX TableView中的可编辑布尔列_Scala_Javafx 2_Scalafx - Fatal编程技术网

ScalaFX TableView中的可编辑布尔列

ScalaFX TableView中的可编辑布尔列,scala,javafx-2,scalafx,Scala,Javafx 2,Scalafx,我是ScalaFx新手,希望创建一个TableView,其中包含带有复选框的可编辑布尔列(以及带有文本字段的可编辑字符串和Int列)。 我想我需要使用CheckBoxTableCell。 我使用的是JDK 7u25、ScalaFX 1.0.0-M4/M5和Scala 2.10.2-final。(我不完全确定ScalaFX版本,但它肯定至少是1.0.0-M5。无论如何,这是Jarek在8月1日上传到的快照。Jarek只编译Scala 2.9.x,但我下载了他的源代码并重新编译了它。) 我已经在sc

我是ScalaFx新手,希望创建一个TableView,其中包含带有
复选框的可编辑布尔列(以及带有文本字段的可编辑字符串和Int列)。
我想我需要使用
CheckBoxTableCell
。 我使用的是JDK 7u25、ScalaFX 1.0.0-M4/M5和Scala 2.10.2-final。(我不完全确定ScalaFX版本,但它肯定至少是1.0.0-M5。无论如何,这是Jarek在8月1日上传到的快照。Jarek只编译Scala 2.9.x,但我下载了他的源代码并重新编译了它。)

我已经在scalafx演示版SimpleTableView的基础上使它工作了一半。但是,我不能在TableView中使用复选框并使用它们的值。相反,我只能让它以这样的方式工作,我需要输入“true”或“false”来编辑表中的值

以下是我迄今为止努力实现的目标:

class Person(firstName_ : String, age_ : Int, cool_ : Boolean) {
  val name = new StringProperty(this, "Name", firstName_)
  val age = new IntegerProperty(this, "Age", age_)
  val cool = new ObjectProperty(this, "Cool", cool)
}

object SimpleEditableTableView extends JFXApp {
  val characters = ObservableBuffer[Person](
    new Person("Peggy", 45, false),
    new Person("Rocky", 43, true)
  )

  stage = new PrimaryStage {
    title = "Simple Ediatble Table View"
    scene = new Scene {
      content = new TableView[Person](characters) {
        editable = true
        columns ++= List(
          new TableColumn[Person, String] {
            text = "Name"
            cellValueFactory = {_.value.name}
            cellFactory = _ => new TextFieldTableCell[Person, String] (new DefaultStringConverter())
            onEditCommit = (evt: CellEditEvent[Person, String]) => {
              val person = evt.rowValue
              val newName = evt.newValue
              println("Here we'll typically save the data. New name = "+newName)
            }
            editable = true
            prefWidth = 180
          },
          new TableColumn[Person, Int] {
            text = "Name"
            cellValueFactory = {_.value.age}
            cellFactory = _ => new TextFieldTableCell[Person, Int] (new IntStringConverter())
            onEditCommit = (evt: CellEditEvent[Person, Int]) => {
              val person = evt.rowValue
              val newAge = evt.newAge
              println("Here we'll typically save the data. New age = "+newAge)
            }
            editable = true
            prefWidth = 180
          },
          new TableColumn[Person, Boolean] {
            text = "Cool"
            cellValueFactory = {_.value.cool}
            cellFactory = _ => new TextFieldTableCell[Person, Boolean] (new BooleanStringConverter())
            onEditCommit = (evt: CellEditEvent[Person, Boolean]) => {
              val person = evt.rowValue
              val newCool = evt.newCool
              println("Here we'll typically save the data. New cool = "+newCool)
            }
            editable = true
            prefWidth = 180
          }
        )
      }
    }
  }
}
对于“酷”表格栏,我想替换

cellFactory = _ => new TextFieldTableCell[Person, Boolean] (new BooleanStringConverter())

为了在TableView中获得好的复选框(目前,我得到了文本字段,我必须在其中键入“true”或“false”)。但是,这给了我一个(明显的)错误:

如果我改变

val selectedProperty: Int => ObservableValue[Boolean, java.lang.Boolean] = {rowNum: Int => model.characters(rowNum).cool}
to val selectedProperty={rowNum:Int=>model.characters(rowNum.cool}


我看到一条错误消息,这基本上归结为这样一个事实:
CheckBoxTableCell.forTableColumn[Person,Boolean](selectedProperty)
要求
selectedProperty
的类型为
Int=>Observalevalue[Boolean,java.lang.Boolean]
,而不是
Int=>ObjectProperty[Boolean]

基本上,您应该使用BooleanProperty,您可以在scalafx用户讨论组发布的同一问题的答案中找到详细信息,包括完整的示例

顺便说一句,ScalaFX是为Scala 2.9.2、2.9.3和2.10构建的,只需按照您发布的链接向下滚动一点,谢谢,我就成功了。我以前尝试过使用java.lang.Boolean和BooleanProperty,而不是ObjectProperty[Boolean],但在
cellValueFactory={{uu.value.cool}
行中遇到了一个错误。现在回想起来,很明显我应该使用
.value.cool.delegate
,而不是
\u value.cool
。我只想知道如何侦听表定义内部的更改,即使用coolcolumn.setOnEditCommit而不是
characters.zipWithIndex.foreach
技巧,但我猜是在模型上侦听,在任何情况下,柱子都比桌子更干净。
type mismatch; found : scalafx.beans.property.ObjectProperty[scala.Boolean] required: scalafx.beans.value.ObservableValue[scala.Boolean,java.lang.Boolean]
val selectedProperty: Int => ObservableValue[Boolean, java.lang.Boolean] = {rowNum: Int => model.characters(rowNum).cool}