Skip to content

Instantly share code, notes, and snippets.

@gantu
Created March 21, 2019 05:15
Show Gist options
  • Save gantu/f6e25c53da261aa1e97742fc8098a255 to your computer and use it in GitHub Desktop.
Save gantu/f6e25c53da261aa1e97742fc8098a255 to your computer and use it in GitHub Desktop.

Revisions

  1. gantu created this gist Mar 21, 2019.
    11 changes: 11 additions & 0 deletions MouseScroll.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    def addMouseScroll[A](comboBox: JComboBox[A]): Unit = {
    comboBox.addMouseWheelListener(new MouseAdapter {
    override def mouseWheelMoved(e: MouseWheelEvent): Unit = {
    val itemCount = comboBox.getItemCount
    val index = comboBox.getSelectedIndex + e.getWheelRotation
    val newIndex = if (index < 0 ) itemCount + index else index % itemCount

    comboBox.setSelectedIndex(newIndex)
    }
    })
    }