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 package ch.hevs.isc.slopify_v2
import java.awt.event.{KeyEvent, KeyListener}
import java.awt.{GridBagConstraints, GridBagLayout, LayoutManager} import java.awt.{GridBagConstraints, GridBagLayout, LayoutManager}
import java.util import java.util
import javax.swing._ import javax.swing._
@ -29,7 +30,11 @@ class GUI extends JFrame {
}) })
val artistsSearchBar: JTextField = new JTextField() 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() val col1Constraints: GridBagConstraints = new GridBagConstraints()
col1Constraints.fill = GridBagConstraints.BOTH col1Constraints.fill = GridBagConstraints.BOTH
@ -94,11 +99,15 @@ class GUI extends JFrame {
val songsSelectionModel: ListSelectionModel = songsTable.getSelectionModel val songsSelectionModel: ListSelectionModel = songsTable.getSelectionModel
songsSelectionModel.addListSelectionListener(e => { songsSelectionModel.addListSelectionListener(e => {
val row: Int = e.getFirstIndex val row: Int = e.getFirstIndex
try {
val songName: String = songsTableModel.getValueAt(row, 0).asInstanceOf[String] val songName: String = songsTableModel.getValueAt(row, 0).asInstanceOf[String]
val song: Option[Song] = curAlbum.get.getSongByTitle(songName) val song: Option[Song] = curAlbum.get.getSongByTitle(songName)
if (song.isDefined) { if (song.isDefined) {
selectSong(song.get) selectSong(song.get)
} }
} catch {
case e: ArrayIndexOutOfBoundsException => {}
}
}) })
val split1: JSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, col1, col2) val split1: JSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, col1, col2)