dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Sep 10, 2001

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Use Mouse Wheel to Control JSpinner


Merlin (JDK1.4) introduces two new features: JSpinner and MouseWheelListener. Sometimes it is convenient to control the spinner values with the mouse wheel. Here's an example:
 
import javax.swing.*;
import java.awt.event.*;
public class TestSpinner extends JFrame implements 
MouseWheelListener
{
  public TestSpinner()
  {
    setSize( 100, 50 );
    spinner = new JSpinner();
    spinner.addMouseWheelListener( this );
    getContentPane().add( spinner, "Center" );
  }
  public void mouseWheelMoved( MouseWheelEvent e )
  {
    spinner.setValue( new Integer( 
((Integer)spinner.getValue()).intValue() - 
e.getWheelRotation() ) );
  }
  public static void main( String [] args )
  {
    TestSpinner t = new TestSpinner();
    t.setVisible( true );
  }
  private JSpinner spinner;
}
Leslie Lu
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date