Tick Spacing

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:

slide = new JSlider( JSlider.HORIZONTAL, 0, 100, 79 );

Tick Spacing

The small vertical lines that calibrate a slider are called tick marks. The longer, thicker marks are major ticks and the thinner marks are minor ticks. The major ticks can be labeled. The spacing between major ticks is set with:

Horizontal Slider
setMajorTickSpacing(int spacing)

and between minor ticks with:

setMinorTickSpacing(int spacing)

The spacing is in terms of the numeric values of the slider.

Bug Note: To have ticks and labels show up on the display, you must call setMajorTickSpacing().

QUESTION 4:

Set the tick spacing of the above slider.

slide = new JSlider( JSlider.HORIZONTAL, 0, 100, 79 );
slide.setMajorTickSpacing( );
slide.setMinorTickSpacing( );