Here you can find the source of handleSliderAdjustmentViaKey(KeyEvent e)
Parameter | Description |
---|---|
e | KeyEvent that has been triggered by the keystroke |
public static void handleSliderAdjustmentViaKey(KeyEvent e)
//package com.java2s; /*/*w w w . j ava 2 s . c om*/ * This Source Code Form is subject to the terms of the * Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.awt.event.KeyEvent; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Main { /** * Checks if a slider has been adjusted by a keystroke. * In this case the changeListener is invoked and valueIsAdjusting is set accordingly. * In this project this is necessary because slider changes are only handled if * getValueIsAdjusting() returns true. * * @param e KeyEvent that has been triggered by the keystroke */ public static void handleSliderAdjustmentViaKey(KeyEvent e) { if (e.getSource() instanceof JSlider) { if (KeyEvent.VK_LEFT == e.getKeyCode() || KeyEvent.VK_RIGHT == e.getKeyCode() || KeyEvent.VK_UP == e.getKeyCode() || KeyEvent.VK_DOWN == e.getKeyCode() || KeyEvent.VK_PAGE_UP == e.getKeyCode() || KeyEvent.VK_PAGE_DOWN == e.getKeyCode() || KeyEvent.VK_HOME == e.getKeyCode() || KeyEvent.VK_END == e.getKeyCode()) { JSlider slider = (JSlider) e.getSource(); for (ChangeListener listener : slider.getChangeListeners()) { slider.setValueIsAdjusting(true); listener.stateChanged(new ChangeEvent(slider)); slider.setValueIsAdjusting(false); } e.consume(); } } } }