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 |
e799. 限制JSlider的数值在标记以内的更多相关文章
- C语言中数组使用负数值的标记
·引 对数组的认知 在c语言中,我们经常使用的一个结构便是数组,在最开始学习数组的时候,它被描述成这样(以一维二维数组为例):一维数组是若干个数连续排列在一起的集合,我们可以通过0-N的标记(N为数组 ...
- e800. 监听JSlider的数值变化
// Create horizontal slider JSlider slider = new JSlider(); // Register a change listener slider.add ...
- Codeforces-Div312
题意:给你n个数,进行*2,/2操作,求解最小操作次数能使所有数相同. 思路:因为数值在100000以内,直接枚举过去,对读入的每一个数,模拟操作,用数组s来存放累计操作步数,数组flag用来标记确 ...
- HTML与CSS网页开发基础
HTML标记语言 HTML文件的创建 整个编译器,或者记事本,文件扩展名改为.htm或者.html HTML文档结构 <html>标记:开头,所有HTML文件以<html>标记 ...
- zookeeper原理解析-数据存储
Zookeeper内存结构 Zookeeper是怎么存储数据的,什么机制保证集群中数据是一致性,在网络异常,当机以及停电等异常情况下恢复数据的,我们知道数据库给我们提供了这些功能,其实zookeepe ...
- FZU 2184 逆序数还原
传送门 Description 有一段时间Eric对逆序数充满了兴趣,于是他开始求解许多数列的逆序数(对于由1...n构成的一种排列数组a,逆序数即为满足i<j,ai>aj的数字对数),但 ...
- 【JAVA 其它流对象】
一.PrintStream类. 该流是字节流. public class PrintStream extends FilterOutputStream implements Appendable, C ...
- ehcache简单使用
项目中需要实现一个功能,定时查询FTP服务器某个目录下的文件,并及时下载至本机,同时不能消耗太多系统资源. 最后实现是使用ehcache,将文件路径和文件大小缓存,如果前后两次无变化,则忽略.如果同一 ...
- 第三章XML简介
概念:XML:提供数据交换.系统配置.内容管理等的功能,可跨平台.跨网络.跨程序的数据描述方式.XSL:依靠XPath定位,提供显示模板,且专门为了显示XML文件信息的语言.CSS(层叠样式表):在网 ...
随机推荐
- C++11 构造函数的改动
一.继承构造函数 继承构造函数的引入原因:如果基类的构造函数很多,那么子类的构造函数想要实现同样多的构造接口,必须一一调用基类的构造函数,有点麻烦. 于是乎:C++11引入继承构造函数,子类可以通过使 ...
- 每日英语:Nelson Mandela Dies at 95
Nelson Mandela, who rose from militant antiapartheid activist to become the unifying president of a ...
- windows操作系统自带的TCP端口转发
假定需要通过192.168.1.8的14941端口连接192.168.1.118的1494端口,则需要在192.168.1.8主机的命令行输入如下语句netsh interface ipv6 ins ...
- js的深入学习课程Object.prototype.toString.call()
1.通过 Object.prototype.toString.call() 进行类型判断 function isArray(obj) { return Object.prototype.toStrin ...
- 3. 文本相似度计算-DSSM算法
1. 文本相似度计算-文本向量化 2. 文本相似度计算-距离的度量 3. 文本相似度计算-DSSM算法 4. 文本相似度计算-CNN-DSSM算法 1. 前言 最近在学习文本相似度的计算,前面两篇文章 ...
- IOS 禁止侧滑返回上个页面功能
1.首先把顶部左侧返回按钮隐藏掉 //隐藏返回按钮 self.navigationItem.hidesBackButton = YES; 2.1.再禁止页面左侧侧 //禁止页面左侧滑动返回,注意,如果 ...
- [EF] 如何在 Entity Framework 中以手动方式设定 Code First 的 Migration 作业
Entity Framework (简称 EF) 发展到现在, 版本已经进入 6.1.0, 距离我写的「在 VS2013 以 Code First 方式建立 EF 资料库」这篇文章已有半年的时间.如果 ...
- 使用 WebSphere ILOG JRules 开发保险应用系统
使用 WebSphere ILOG JRules 开发保险应用系统 概述 保险行业在国内是一个充分竞争的行业,竞争的加剧导致保险公司的业务管理等各项费用在增长.而保险公司业务支撑系统的先进性与灵活支撑 ...
- [转]ORA-01555错误总结(二)
原文地址:http://blog.csdn.net/oradh/article/details/25683769 这篇文章紧接着上一篇“ORA-01555错误总结(一)”,主要描述延迟块清除导致的OR ...
- [转]你所不知的 CSS ::before 和 ::after 伪元素用法
SS 有两个说不上常用的伪类 :before 和 :after,偶尔会被人用来添加些自定义格式什么的,但是它们的功用不仅于此.前几天发现了 Creative Link Effects 这个非常有意思的 ...