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
.
精彩评论