How to change ListView content in Scala?

I am trying to write a mini file browser where I show a list of files, and replace the list with 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 the event, I want to change the displayed content. Most of what I tried makes the list β€œinvisible” (but still responds with a choice of up and down arrows) - sometimes by making items invisible only when they are selected!

How to update ListView to reflect new ListBuffer content? Or can someone point me to an example of this?

Thank.

+1
source share
2 answers

It works:

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
      }
    }
  }
}
+6
source

Challenge myListView.listData = myListBuffer.

+2

All Articles