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.
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)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment