package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.metal.MetalSliderUI;
import com.sun.java.swing.plaf.windows.WindowsSliderUI;

public final class MainPanel extends JPanel {
    private static final double MAXD = .8;
    private static final int MAXI = (int) (100 * MAXD);
    private MainPanel() {
        super(new GridLayout(2, 1, 5, 5));

        JSlider slider1 = makeSilder("ChangeListener");
        JSlider slider2 = makeSilder("TrackListener");
        if (slider2.getUI() instanceof WindowsSliderUI) {
            slider2.setUI(new WindowsDragLimitedSliderUI(slider2));
        } else {
            slider2.setUI(new MetalDragLimitedSliderUI());
        }
        add(slider1);
        add(slider2);
        setPreferredSize(new Dimension(320, 240));
    }
    private static JSlider makeSilder(String title) {
        JSlider slider = new JSlider(0, 100, 40);
        slider.setBorder(BorderFactory.createTitledBorder(title));
        slider.setMajorTickSpacing(10);
        slider.setPaintTicks(true);
        slider.setPaintLabels(true);
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            Enumeration elements = dictionary.elements();
            while (elements.hasMoreElements()) {
                JLabel label = (JLabel) elements.nextElement();
                int v = Integer.parseInt(label.getText());
                if (v > MAXI) {
                    label.setForeground(Color.RED);
                }
            }
        }
        slider.getModel().addChangeListener(new ChangeListener() {
            @Override public void stateChanged(ChangeEvent e) {
                BoundedRangeModel m = (BoundedRangeModel) e.getSource();
                if (m.getValue() > MAXI) {
                    m.setValue(MAXI);
                }
            }
        });
        return slider;
    }
    private static class WindowsDragLimitedSliderUI extends WindowsSliderUI {
        protected WindowsDragLimitedSliderUI(JSlider slider) {
            super(slider);
        }
        @Override protected TrackListener createTrackListener(JSlider slider) {
            return new TrackListener() {
                @Override public void mouseDragged(MouseEvent e) {
                    //case HORIZONTAL:
                    int halfThumbWidth = thumbRect.width / 2;
                    int trackLeft   = trackRect.x - halfThumbWidth;
                    int maxPos = trackLeft + (int) (.5 + trackRect.width * MAXD);
                    if (e.getX() > maxPos) {
                        offset = 0;
                        MouseEvent me = new MouseEvent(
                            e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(),
                            maxPos, e.getY(),
                            e.getXOnScreen(), e.getYOnScreen(),
                            e.getClickCount(), e.isPopupTrigger(), e.getButton());
                        e.consume();
                        super.mouseDragged(me);
                    } else {
                        super.mouseDragged(e);
                    }
                }
            };
        }
    }
    private static class MetalDragLimitedSliderUI extends MetalSliderUI {
        @Override protected TrackListener createTrackListener(JSlider slider) {
            return new TrackListener() {
                @Override public void mouseDragged(MouseEvent e) {
                    //case HORIZONTAL:
                    int halfThumbWidth = thumbRect.width / 2;
                    int trackLeft   = trackRect.x - halfThumbWidth;
                    int maxPos = trackLeft + (int) (.5 + trackRect.width * MAXD);
                    if (e.getX() > maxPos) {
                        offset = 0;
                        MouseEvent me = new MouseEvent(
                            e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(),
                            maxPos, e.getY(),
                            e.getXOnScreen(), e.getYOnScreen(),
                            e.getClickCount(), e.isPopupTrigger(), e.getButton());
                        e.consume();
                        super.mouseDragged(me);
                    } else {
                        super.mouseDragged(e);
                    }
                }
            };
        }
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -381,80 +381,21 @@
 nal 
-double MAXD = .8;%0A    private static final int MAXI = (int) (100 * MAXD)
+int MAXI = 80
 ;%0A  
@@ -2470,49 +2470,36 @@
 nt t
-rack
+humb
 Left 
-  = trackRect.x - halfThumbWidth
+= e.getX() - offset
 ;%0A  
@@ -2533,55 +2533,48 @@
 s = 
-trackLeft + (int) (.5 + trackRect.width * MAXD)
+xPositionForValue(MAXI) - halfThumbWidth
 ;%0A  
@@ -2591,32 +2591,33 @@
         if (
-e.getX()
+thumbLeft
  %3E maxPos) %7B
@@ -2636,35 +2636,48 @@
             
+ int x = maxPos +
  offset
- = 0
 ;%0A          
@@ -2830,38 +2830,33 @@
                 
-maxPos
+x
 , e.getY(),%0A    
@@ -3622,49 +3622,36 @@
 nt t
-rack
+humb
 Left 
-  = trackRect.x - halfThumbWidth
+= e.getX() - offset
 ;%0A  
@@ -3685,55 +3685,48 @@
 s = 
-trackLeft + (int) (.5 + trackRect.width * MAXD)
+xPositionForValue(MAXI) - halfThumbWidth
 ;%0A  
@@ -3747,24 +3747,25 @@
     if (
-e.getX()
+thumbLeft
  %3E maxPo
@@ -3796,19 +3796,32 @@
     
+ int x = maxPos +
  offset
- = 0
 ;%0A  
@@ -3990,22 +3990,17 @@
         
-maxPos
+x
 , e.getY

use BasicSliderUI#xPositionForValue(...)