Class WheelSpinner

All Implemented Interfaces:
MouseWheelListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class WheelSpinner extends JSpinner implements MouseWheelListener
A JSpinner with mousewheel support, and some convenience methods.

Supports only SpinnerListModel and SpinnerNumberModel. Mouse-wheel support is enabled according to GeneralUISettings. If model is a SpinnerNumberModel prevent insertion of anything except digit.

See Also:
  • Constructor Details

    • WheelSpinner

      public WheelSpinner()
  • Method Details

    • setBlockKeyEventForwarding

      public void setBlockKeyEventForwarding(boolean b)
      Block/unblock key event forwarding for printable keys.

      Key presses are not consumed by JSpinner , they are also processed by the keybinding framework. The Only way is to capture all the keys... /* see https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

      Parameters:
      b -
    • isBlockKeyEventForwarding

      public boolean isBlockKeyEventForwarding()
      Returns:
      False by default.
    • setModel

      public void setModel(SpinnerModel model)
      Overrides:
      setModel in class JSpinner
      Parameters:
      model - Must be an instance of SpinnerListModel or SpinnerNumberModel.
    • getDefaultEditor

      public JSpinner.DefaultEditor getDefaultEditor()
    • setValue

      public void setValue(Object value, boolean silent)
      Same as setValue(Object) but with possibility of NOT notifying change listeners.
      Parameters:
      value -
      silent - If true don't notify registered ChangeListeners
    • isLoopValues

      public boolean isLoopValues()
      Indicate if spinner loops to min value when max value is reached using the wheel.
      Returns:
      the loopValues
    • setLoopValues

      public void setLoopValues(boolean loopValues)
      Set whether to loop to min value when max value is reached using the wheel.
      Parameters:
      loopValues - the loopValues to set
    • setColumns

      public void setColumns(int n)
      Set the width of the editor so it can display n chars.
      Parameters:
      n - int
    • getColumns

      public int getColumns()
    • getWheelStep

      public int getWheelStep()
      Returns:
      the wheelStep
    • setWheelStep

      public void setWheelStep(int wheelStep)
      Parameters:
      wheelStep - the wheelStep to set
    • getCtrlWheelStep

      public int getCtrlWheelStep()
      Wheel step used when ctrl is pressed.
      Returns:
      the ctrlWheelStep
    • setCtrlWheelStep

      public void setCtrlWheelStep(int ctrlWheelStep)
      Wheel step used when ctrl is pressed.
      Parameters:
      ctrlWheelStep - the ctrlWheelStep to set
    • isChangeFromManualEdit

      public boolean isChangeFromManualEdit()
      Check if the last ChangeEvent resulted from a manual edit (user typed value), or an increment/decrement action (e.g. using the up/down buttons).

      Note: this may not work on all L&F, works at least on Netbeans flatlaf dark.

      Returns:
    • commitEdit

      public void commitEdit() throws ParseException
      Overridden only to manage changeFromManualEdit.
      Overrides:
      commitEdit in class JSpinner
      Throws:
      ParseException
    • mouseWheelMoved

      public void mouseWheelMoved(MouseWheelEvent e)
      Specified by:
      mouseWheelMoved in interface MouseWheelListener