Created
March 21, 2019 05:15
-
-
Save gantu/f6e25c53da261aa1e97742fc8098a255 to your computer and use it in GitHub Desktop.
Revisions
-
gantu created this gist
Mar 21, 2019 .There are no files selected for viewing
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 charactersOriginal 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) } }) }