made search field react on keypress

This commit is contained in:
Louis Heredero 2024-05-07 14:31:14 +02:00
parent 96bbef8bbd
commit e165367133
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7

View File

@ -1,5 +1,6 @@
package ch.hevs.isc.slopify_v2
import java.awt.event.{KeyEvent, KeyListener}
import java.awt.{GridBagConstraints, GridBagLayout, LayoutManager}
import java.util
import javax.swing._
@ -29,7 +30,11 @@ class GUI extends JFrame {
})
val artistsSearchBar: JTextField = new JTextField()
artistsSearchBar.addActionListener(_ => updateArtistsSearch())
artistsSearchBar.addKeyListener(new KeyListener {
override def keyTyped(keyEvent: KeyEvent): Unit = {}
override def keyPressed(keyEvent: KeyEvent): Unit = {}
override def keyReleased(keyEvent: KeyEvent): Unit = updateArtistsSearch()
})
val col1Constraints: GridBagConstraints = new GridBagConstraints()
col1Constraints.fill = GridBagConstraints.BOTH
@ -94,10 +99,14 @@ class GUI extends JFrame {
val songsSelectionModel: ListSelectionModel = songsTable.getSelectionModel
songsSelectionModel.addListSelectionListener(e => {
val row: Int = e.getFirstIndex
val songName: String = songsTableModel.getValueAt(row, 0).asInstanceOf[String]
val song: Option[Song] = curAlbum.get.getSongByTitle(songName)
if (song.isDefined) {
selectSong(song.get)
try {
val songName: String = songsTableModel.getValueAt(row, 0).asInstanceOf[String]
val song: Option[Song] = curAlbum.get.getSongByTitle(songName)
if (song.isDefined) {
selectSong(song.get)
}
} catch {
case e: ArrayIndexOutOfBoundsException => {}
}
})