The slider supports two levels of tick marks, major and minor. Typically, the minor tick-mark spacing is smaller than the major tick-mark spacing. Also, the minor tick-mark spacing is a multiple of the major tick-mark spacing. However, the slider does not enforce any of these constraints.

    // Create a horizontal slider that moves left-to-right
    JSlider slider = new JSlider();
    // Determine if currently showing ticks
    boolean b = slider.getPaintTicks(); // false
    
    // Show tick marks
    slider.setPaintTicks(true);
    
    // Set major tick marks every 25 units
    int tickSpacing = 25;
    slider.setMajorTickSpacing(tickSpacing);
    
    // Set minor tick marks every 5 units
    tickSpacing = 5;
    slider.setMinorTickSpacing(tickSpacing);

 

Related Examples

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2021-07-17
  • 2021-10-19
  • 2021-10-16
相关资源
相似解决方案