United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6923305 SynthSliderUI paints the slider track when the slider's "paintTrack" property is set to false
JDK-6923305 : SynthSliderUI paints the slider track when the slider's "paintTrack" property is set to false

Details
Type:
Bug
Submit Date:
2010-02-04
Status:
Resolved
Updated Date:
2012-03-22
Project Name:
JDK
Resolved Date:
2010-03-17
Component:
client-libs
OS:
generic
Sub-Component:
javax.swing
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u10,7
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
The SynthSliderUI class invokes the paintTrack method even though the "paintTrack" property of a slider component being painted was set to false. The spec on the JSlider.html#setPaintTrack(boolean) says that the method controls whether or not to paint the slider track.

Here is a sample program that demonstrates this:

------------------
import javax.swing.*;
import javax.swing.plaf.synth.*;
import java.awt.*;

public class Test {

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                runTest();
            }
        });
    }

    private static void runTest() {
        try {
            UIManager.setLookAndFeel(new SynthLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            throw new RuntimeException(e);
        }
        JSlider slider = new JSlider();
        slider.setPaintTrack(false);
        slider.setUI(new SynthSliderUI(slider) {

            @Override
            protected void paintTrack(SynthContext context, Graphics g,
                    Rectangle trackBounds) {
                super.paintTrack(context, g, trackBounds);
                System.out.println("paintTrack called");
            }

        });
        JFrame jFrame = new JFrame();
        jFrame.getContentPane().add(slider);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.pack();
        jFrame.setVisible(true);
    }
}
--------------------

                                    

Comments
EVALUATION

The SynthSliderUI#paintTrack method shouldn't be invoked in case the paintTrack property is false. A part of the BasicSliderUI#paint method can be an example of correct code:

        if ( slider.getPaintTrack() && clip.intersects( trackRect ) ) {
            paintTrack( g );
        }
                                     
2010-02-19



Hardware and Software, Engineered to Work Together