made search field react on keypress
This commit is contained in:
		| @@ -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,10 +99,14 @@ 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 | ||||||
|     val songName: String = songsTableModel.getValueAt(row, 0).asInstanceOf[String] |     try { | ||||||
|     val song: Option[Song] = curAlbum.get.getSongByTitle(songName) |       val songName: String = songsTableModel.getValueAt(row, 0).asInstanceOf[String] | ||||||
|     if (song.isDefined) { |       val song: Option[Song] = curAlbum.get.getSongByTitle(songName) | ||||||
|       selectSong(song.get) |       if (song.isDefined) { | ||||||
|  |         selectSong(song.get) | ||||||
|  |       } | ||||||
|  |     } catch { | ||||||
|  |       case e: ArrayIndexOutOfBoundsException => {} | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user