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(层叠样式表):在网 ...
随机推荐
- DCOS :私有云的物理基础架构管理引擎
https://cloud.tencent.com/developer/article/1005598 一.引言 云计算经过多年的发展,逐渐从概念到渐为人认知.到接受.到现在全行业拥抱上云,云的客户也 ...
- redis使用日志(4):如何让外部服务器访问
开启redis 允许外网IP 访问 在 Linux 中安装了redis 服务,当在客户端通过远程连接的方式连接时,报could not connect错误. 错误的原因很简单,就是没有连接上redis ...
- 一次tomcat配置参数调优Jmeter压力测试记录前后对比
使用的tomcat版本为:apache-tomcat-7.0.53 使用测试工具Jmeter版本为:apache-jmeter-2.12 1.测试前tomat的"server.xml&quo ...
- pom.xml里发布和下载包
1.下载包 在<project>标签中 <repositories> <repository> <id>nexus</id> <url ...
- 关于fork()函数的精辟分析
http://blog.csdn.net/yanh_lzu/article/details/2311644 第一贴:cu上关于fork()函数的精辟分析 声明:在别人的博客上看到这篇文章,真的很精 ...
- Oracle sql%rowcount 返回影响行数;sql server @@RowCount返回影响行数
sql server中,返回影响行数是:If @@RowCount<1 Oracle中,返回影响行数是:If sql%rowcount<1 例: sqlserver: create pro ...
- 【Turing Award】Robin Milner And Butler W. Lampson
1991 罗宾·米尔纳(Robin Milner) Robin Milner(13 January 1934 – 20 March 2010) Introduction : Milner was bo ...
- virtual box 5.2.12 扩展包安装
http://download.virtualbox.org/virtualbox/ 找到对应版本的virulbox去下载就可以了
- javascript中json对象长度
JSON中无法使用length去获取长度,length只针对数组对象适用: var data={"showdata":{"中国人民大学":{"2013 ...
- CSS网页布局中易犯的30个小错误
即使是CSS高手,也难免在书写CSS代码的时候出一些小错误,或者说,任何一种代码都是如此.小错误却往往造成大问题,浪费很多无辜的时间来调试和排错.查看下面这份CSS网页布局中易犯的10个小错误,努力的 ...