开发者

How do I change the contents of a ListView in Scala?

开发者 https://www.devze.com 2023-03-22 09:31 出处:网络
I\'m trying to write a mini file browser, where I display a list of files, and replace the list by another when I change directories.

I'm trying to write a mini file browser, where I display a list of files, and replace the list by another when I change directories.

I can display a list:

val myList = List("Paris", "New York", "Tokyo", "Berlin", "Copenhagen")
val myListBuffer = new ListBuffer[String] ()
myListBuffer.appendAll(myList)
val myListView = new ListView(myListBuffer)
...
contents += myListView

In response to an event, I want to change the displayed contents. Most of what I've tried makes the list "invisible" (but still responding to selection by up and down arrows)--sometimes by making elements invisible only when they are selected!

How do I update the ListView to reflect the new contents of the ListBuffer? Or can someone point me to an example of this?

开发者_如何学编程

Thanks.


This seems to work:

object LVTest extends SimpleSwingApplication {

  def top = new MainFrame {
    contents = myListView
    size = new Dimension(200, 200)
  }

  val myListView = new ListView[String]() {
    val myListBuffer = ListBuffer("Paris", "New York", "Tokyo", "Berlin", "Copenhagen")
    listData = myListBuffer
    listenTo(mouse.clicks)
    reactions += {
      case e: MouseClicked => {
        myListBuffer += "Slough"
        listData = myListBuffer
      }
    }
  }
}


Call myListView.listData = myListBuffer.

0

精彩评论

暂无评论...
验证码 换一张
取 消