日期:2014-05-20  浏览次数:20666 次

关于SliderPanel中的setPaintTicks()疑问!
package   src;
import   javax.swing.*;
import   javax.swing.event.*;
import   java.awt.*;
import   java.awt.event.*;

public   class   SliderPanel   extends   JPanel   implements   ChangeListener{
public   SliderPanel(){
setLayout(new   BorderLayout());

JSlider   slider1=new   JSlider(JSlider.VERTICAL,0,100,50);//水平标尺,0到100默认在50位置上.0位于左方.
slider1.addChangeListener(this);
slider1.setMajorTickSpacing(10);
slider1.setMinorTickSpacing(2);
slider1.setPaintTicks(true);     //我设置false也没见视图有什么变化?试问怎在代码中起着什么作用?
add(slider1,BorderLayout.EAST);

JSlider   slider2=new   JSlider(JSlider.VERTICAL,0,100,50);
slider2.addChangeListener(this);
slider2.setMajorTickSpacing(10);   //主刻度尺分度.
slider2.setMinorTickSpacing(2);     //小刻度尺分度.
slider2.setPaintTicks(true);
add(slider2,BorderLayout.WEST);

JSlider   slider3=new   JSlider(JSlider.HORIZONTAL,0,100,50);//垂直标尺,0到100默认在50位置上.0位于下方.
slider3.addChangeListener(this);
slider3.setMajorTickSpacing(10);
slider3.setMinorTickSpacing(2);
slider3.setPaintTicks(true);
add(slider3,BorderLayout.SOUTH);

JSlider   slider4=new   JSlider(JSlider.HORIZONTAL,0,100,50);
slider4.addChangeListener(this);
slider4.setMajorTickSpacing(10);
slider4.setMinorTickSpacing(2);
slider4.setPaintTicks(false);
add(slider4,BorderLayout.NORTH);

}
public   void   stateChanged(ChangeEvent   e){
JSlider   js=(JSlider)(e.getSource());
System.out.println(js.getValue());

}
public   static   void   main(String[]   args)   {
JFrame   f   =   new   JFrame   ( "SliderPanel   Example ");
        JPanel   j   =   new   SliderPanel();
       
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        f.getContentPane().add   (j,   BorderLayout.CENTER);
        f.setSize   (300,   300);
        f.setVisible(true);
}
}

------解决方案--------------------
关注。。。。