zoukankan      html  css  js  c++  java
  • e799. 限制JSlider的数值在标记以内

    By default, the slider can take on any value from the minimum to the maximum. It is possible to configure the slider to allow only values at tick marks (see e797 显示JSlider的标记). This is done by calling JSlider.setSnapToTicks(true).

    The slider's minimum and minor tick-mark spacing determines what values are possible. For example, if the minimum is 3 and the minor tick-mark spacing is 10, only the values, 3, 13, 23, and so forth, are allowed. If a minor tick-mark spacing has not been set, the major tick-mark spacing is used. If neither a minor nor a major tick mark spacing has been set, a tick-mark spacing of 1 is assumed.

    Calling setSnapToTicks() also has the effect of causing the slider's knob to snap to the closest tick mark whenever it is dragged or programmatically moved to a spot between tick marks.

        // Create a horizontal slider that moves left-to-right
        JSlider slider = new JSlider();
        // 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);
        
        // Show tick marks
        slider.setPaintTicks(true);
        
        // Determine if currently snapping to tick marks
        boolean b = slider.getSnapToTicks(); // false
        
        // Snap to tick marks
        slider.setSnapToTicks(true);
        
        // Set to a spot between tick marks; the value moves to closest tick mark
        slider.setValue(27);
        int value = slider.getValue();  // 25
    
    Related Examples
  • 相关阅读:
    routine 程序;日常工作|日常的;例行的
    have great expectation of 寄予厚望
    数据库总结十完整性约束
    Spoken Language One
    Stature 身高,身材;(精神、道德等的)高度
    ultimate与estimate
    dramatically 从戏剧角度;戏剧性地,显著地
    predestined 注定的
    How to lists.
    endanger 危及;使遭到危险
  • 原文地址:https://www.cnblogs.com/borter/p/9596240.html
Copyright © 2011-2022 走看看