Bryan Liew
Bryan Liew

Reputation: 1

ScalaFX | ListView | How do I select all item in listview using selectionModel()?

I want to come up with a messaging app. Right now, it works for 1 to 1 conversation. However, I am trying to come up with a button that broadcasts the message to everyone.

I am thinking to use MultipleSelectionModel() to select all items in listView. However, MultipleSelectionModel() is not a member of listview. (selectionModel is though)

Here is what I have come up with so far

package com.hep88.view
import akka.actor.typed.ActorRef
import scalafxml.core.macros.sfxml
import scalafx.event.ActionEvent
import scalafx.scene.control.{Label, ListView, TextField}
import com.hep88.ChatClient
import com.hep88.User
import com.hep88.Group
import com.hep88.Client
import scalafx.collections.ObservableBuffer
import scalafx.Includes._
@sfxml
class MainWindowController(private val txtName: TextField,
private val lblStatus: Label, private val listUser: ListView[User],
private val lblGStatus: Label, private val listGroup: ListView[Group],
private val listMessage: ListView[String],
private val txtMessage: TextField) {

    def handleSend(actionEvent: ActionEvent): Unit ={

if (listUser.selectionModel().selectedIndex.value >= 0){
  Client.greeterMain ! ChatClient.SendMessageL(listUser.selectionModel().selectedItem.value.ref,
    txtMessage.text())
}

}

I am trying to do something like

Client.greeterMain ! ChatClient.SendMessageL(listUser.multipleSelectionModel().selectall.value.ref,
     txtMessage.text())

Obviously, it didn't work. Any suggestions on how can I get this to work?

Upvotes: 0

Views: 168

Answers (0)

Related Questions