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

e799. 限制JSlider的数值在标记以内的更多相关文章

  1. C语言中数组使用负数值的标记

    ·引 对数组的认知 在c语言中,我们经常使用的一个结构便是数组,在最开始学习数组的时候,它被描述成这样(以一维二维数组为例):一维数组是若干个数连续排列在一起的集合,我们可以通过0-N的标记(N为数组 ...

  2. e800. 监听JSlider的数值变化

    // Create horizontal slider JSlider slider = new JSlider(); // Register a change listener slider.add ...

  3. Codeforces-Div312

    题意:给你n个数,进行*2,/2操作,求解最小操作次数能使所有数相同. 思路:因为数值在100000以内,直接枚举过去,对读入的每一个数,模拟操作,用数组s来存放累计操作步数,数组flag用来标记确 ...

  4. HTML与CSS网页开发基础

    HTML标记语言 HTML文件的创建 整个编译器,或者记事本,文件扩展名改为.htm或者.html HTML文档结构 <html>标记:开头,所有HTML文件以<html>标记 ...

  5. zookeeper原理解析-数据存储

    Zookeeper内存结构 Zookeeper是怎么存储数据的,什么机制保证集群中数据是一致性,在网络异常,当机以及停电等异常情况下恢复数据的,我们知道数据库给我们提供了这些功能,其实zookeepe ...

  6. FZU 2184 逆序数还原

    传送门 Description 有一段时间Eric对逆序数充满了兴趣,于是他开始求解许多数列的逆序数(对于由1...n构成的一种排列数组a,逆序数即为满足i<j,ai>aj的数字对数),但 ...

  7. 【JAVA 其它流对象】

    一.PrintStream类. 该流是字节流. public class PrintStream extends FilterOutputStream implements Appendable, C ...

  8. ehcache简单使用

    项目中需要实现一个功能,定时查询FTP服务器某个目录下的文件,并及时下载至本机,同时不能消耗太多系统资源. 最后实现是使用ehcache,将文件路径和文件大小缓存,如果前后两次无变化,则忽略.如果同一 ...

  9. 第三章XML简介

    概念:XML:提供数据交换.系统配置.内容管理等的功能,可跨平台.跨网络.跨程序的数据描述方式.XSL:依靠XPath定位,提供显示模板,且专门为了显示XML文件信息的语言.CSS(层叠样式表):在网 ...

随机推荐

  1. 简单的sqlhelper的学习日志

    一:今天做了一个简单的sqlhelper,还有调用,将今天学的内容总结一下,解决方案如下: 二:对应的sqlhelper的内容: using System; using System.Collecti ...

  2. LeetCode:Sqrt(x) 解题报告

    Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. SOLUTION 1: 参见:二分法总结,以及模 ...

  3. 确保安全的HTTPS(使用混合加密的HTTPS,前端面试常问)第二篇

    苹果已经确定,在iOS9中通信机制采用HTTPS了. 第一篇:http://www.cnblogs.com/ziyi--caolu/p/4742577.html 上一篇详细介绍了为什么要对HTTP进行 ...

  4. pymongo 使用测试

    >>> import pymongo >>> uri = "mongodb://recall:123456@oceanic.mongohq.com:100 ...

  5. ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN

    问题描述:FatalListenerStartupException: Authentication failure 问题原因:连接RabbitMQ服务器异常,要么是用户名和密码错误,要么是使用的用户 ...

  6. iOS手机号,身份证,车牌号正则表达式

    1.手机号判断,根据维基百科2016年6月修订的段号判断 是否是手机号 /** 手机号码 13[0-9],14[5|7|9],15[0-3],15[5-9],17[0|1|3|5|6|8],18[0- ...

  7. jquery chosen api

    title prev Chosen 选项列表 demo.html Chosen 选项列表 通过参数传递的选项 以下参数在实例化的时候通过参数设置. $('.my_select_box').chosen ...

  8. golang深度获取子节点

    起因 需要在树形结构里获取子树,树形结构一般是存储一维数组,数组元素里存储子节点的指针 代码 package main import ( "errors" "fmt&qu ...

  9. jython 2.7.1 版本开发历史

    很多技术一直感兴趣,在工作中没有太多实践的机会,但可以持续关注.Jython最初是Python on JVM,所以最初的名称是JPython,后续由于基于JVM可以有更多可能性,名字改为Jython. ...

  10. [uart]设置linux 串口的block方式

    1. 如果设置为非block模式: open(device, O_RDWR | O_NDELAY | O_NONBLOCK); 2. 如果设置为block模式,且读固定字节数返回则termios.c_ ...