#navi(contents-page-name): No such page: ST

FrontPage>Swing Tips>ST/MouseWheel

ST/MouseWheel

Terai Atsuhiro 2021-11-26 (金) 05:14:30

#ref(): File not found: "wheel.png" at page "Swing/MouseWheel"

spinner.addMouseWheelListener(new MouseWheelListener(){
  public void mouseWheelMoved(MouseWheelEvent e){
    JSpinner source = (JSpinner)e.getSource();
    SpinnerNumberModel model = (SpinnerNumberModel)source.getModel();
    Integer oldValue = (Integer)source.getValue();
    int intValue = oldValue.intValue()
                  -e.getWheelRotation()*model.getStepSize().intValue();
    Integer newValue = new Integer(intValue);
    if(model.getMaximum().compareTo(newValue)>=0 &&
       model.getMinimum().compareTo(newValue)<=0){
      source.setValue(newValue);
    }
  }
});