Displaying the tick value of a JSlider as the slider is being moved

Add a ChangeListener to your JSlider and implement the method stateChanged. Here’s an example:

Main.java:

import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
   
public class Main extends JFrame {
   public Main() {
      getContentPane().setLayout(new FlowLayout());
    
      // notice this components is final because
      // it is being used in an inner class
      final JTextField value = new JTextField(5);
 
      final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 30, 15);
      // draw the major tick marks (one for every tick label)
      slider.setMajorTickSpacing(10);
      // draw the minor tick marks (between the tick labels)
      slider.setMinorTickSpacing(1);
      // draw the tick marks
      slider.setPaintTicks(true);
      // draw the tick mark labels
      slider.setPaintLabels(true);
 
      slider.addChangeListener(new ChangeListener() {
         public void stateChanged(ChangeEvent ce) {
            value.setText(""+slider.getValue());
         }
      });
 
      getContentPane().add(value);
      getContentPane().add(slider);
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent event) {
            System.exit(0);   
         }      
      });
 
      pack();
   }
 
   public static void main(String[] args) {
      (new Main()).show();
   }
}