Other Useful Slider Methods

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

source = (JSlider)evt.getSource() ;

if ( !source.getValueIsAdjusting() )
{
  if ( source.getName()().equals("sliderA") )
    textA.setText( source.getValue() + " " );
  if ( source.getName()().equals("sliderB") )
    textB.setText( source.getValue() + " " );
}

For fun, modify the previous program to see the result of this patch.

Other Useful Slider Methods

Here are a few other sometimes useful methods from class JSlider. For additional discussion go to How to Use Sliders in Sun's on-line Java Tutorial.

int getMaximum()   
    // Returns the maximum value supported by the slider. 
int getMinimum()   
    // Returns the minimum value supported by the slider. 

These two methods are useful when the application methods must scale their output proportional to the possible range of values.

void setInverted(boolean b) 
    //Set to true to reverse the order of values on the slider 

This method with a horizontal slider makes the values ascend going from right to left (the revers of the usual order).

QUESTION 14:

Is it possible to disable a slider?