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(层叠样式表):在网 ...
随机推荐
- Java 必须掌握的 12 种 Spring 常用注解!
1.声明bean的注解 @Component 组件,没有明确的角色 @Service 在业务逻辑层使用(service层) @Repository 在数据访问层使用(dao层) @Controller ...
- [SQL Server 2014] 微软将于年底发布新版数据库SQL Server 2014
在今年的TechEd大会上,微软宣布SQL Server 2014的第一个技术预览版.SQL Server 2014的重点包括内存OLTP.实时的大数据分析.支持混合云端,以及提供更完整的商业智能(B ...
- 每日英语:American Cities May Have Hit 'Peak Office'
Despite some hype and a few regional exceptions, the construction of office towers and suburban offi ...
- LeetCode: Maximum Subarray 解题报告
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
- 第一个驱动之字符设备驱动(二)mdev
mdev是busybox提供的一个工具,用在嵌入式系统中,相当于简化版的udev,作用是在系统启动和热插拔或动态加载驱动程序时, 自动创建设备节点.文件系统中的/dev目录下的设备节点都是由mdev创 ...
- c#中日期格式化
c#的日期格式化比较简单,在ToString中设置日期格式即可 DateTime.Now.ToLocalTime().ToString("yyyy_MM_dd_hh_mm_ss") ...
- C#中遍历Hashtable的4种方法
static void Main(string[] args) { Hashtable ht=new Hashtable(); ht.Add("); ht.Add("); ht.A ...
- TCP、UDP数据包大小的限制
版权声明:本文为灿哥哥http://blog.csdn.net/caoshangpa 原创文章,转载请标明出处. https://blog.csdn.net/caoshangpa/article/de ...
- 3. Recursive AutoEncoder(递归自动编码器)
1. AutoEncoder介绍 2. Applications of AutoEncoder in NLP 3. Recursive Autoencoder(递归自动编码器) 4. Stacked ...
- Git CMD连接,管理(remote,add,commit,push)github repository
git initmd testcd testgit statusgit add test //git add test/a.txtgit status git remote add origin g ...