Created
March 21, 2019 05:15
-
-
Save gantu/f6e25c53da261aa1e97742fc8098a255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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