e791. 为JSpinner定制编辑器
This example replaces the default editor (a JFormattedTextField) in a spinner component with a custom editor. The custom editor is simply a panel that displays a color. The name of the color to display is stored in a SpinnerListModel.
// Create a color spinner
ColorSpinner spinner = new ColorSpinner(
new String[]{"red", "green", "blue"}); // Change the selected color
spinner.setValue("blue"); public class ColorSpinner extends JSpinner {
public ColorSpinner(String[] colorNames) {
super();
setModel(new SpinnerListModel(colorNames));
setEditor(new Editor(this));
} public class Editor extends JPanel implements ChangeListener {
int preferredWidth = 30;
int preferredHeight = 16; Editor(JSpinner spinner) {
// Add the listener
spinner.addChangeListener(this); // Set the preferred size
setPreferredSize(new Dimension(preferredWidth, preferredHeight)); // Display the current color
setColor((String)spinner.getValue());
} // Handles changes to the value stored in the model
public void stateChanged(ChangeEvent evt) {
JSpinner spinner = (JSpinner)evt.getSource(); // Get the new value
String value = (String)spinner.getValue(); // Update the displayed color
setColor(value);
} // Updates the displayed color to 'colorName' which must be one
// of the predefined colors in java.awt.Color.
public void setColor(String colorName) {
try {
// Find the field and value of colorName
Field field = Class.forName("java.awt.Color").getField(colorName);
Color color = (Color)field.get(null); // Display the color
setBackground(color);
} catch (Exception e) {
}
}
}
| Related Examples |
e791. 为JSpinner定制编辑器的更多相关文章
- Atom 编辑器试用
简介 它号称"21世纪可黑客的文本编辑器".GitHub支持并开源,并支持跨平台.和brackets编辑器一样基于浏览器开发,意味着你可以使用less(包含css)来定制编辑器界面 ...
- Python 开发的 IDE 和代码编辑器,你选择的哪一个?
为了方便,我会分两个大类去说明,一类是适用于软件开发的比较通用的编辑器或 IDE ,我们可以通过插件等形式支持 Python 的开发,另一个是专注于 Python 开发的编辑器或 IDE . 不过在此 ...
- Html引入百度富文本编辑器ueditor
在日常工作用,肯定有用到富文本编辑器的时候,富文本编辑器功能强大使用方便,我用的是百度富文本编辑器,首先需要下载好百度编辑器的demo, 然后创建ueditor.html文件,引入百度编辑器,然后在h ...
- Html引入百度富文本编辑器ueditor及自定义工具栏
在日常工作用,肯定有用到富文本编辑器的时候,富文本编辑器功能强大使用方便,我用的是百度富文本编辑器,首先需要下载好百度编辑器的demo, 然后创建ueditor.html文件,引入百度编辑器,然后在h ...
- notepad++与vivado关联
notepad++与vivado关联 打开vivado软件,选择菜单栏“Tools——>Options…”,在弹出的对话框中,选择General选项卡,如图1所示. 图1 选择General选 ...
- 【转载】UEditor前端配置项说明
UEditor 的配置项分为两类:前端配置项 和 后端配置项 后端配置项具体看这个文档L:后端配置项说明 本文档介绍如何通过设置前端配置项,定制编辑器的特性,配置方法主要通过修改ueditor.con ...
- 关于Eclipse Modeling Framework 实现模型驱动开发,第一部分
======================================EMF第二篇文章========================= 用 Eclipse Modeling Framework ...
- 重拾《 两周自制脚本语言 》- Eclipse插件实现语法高亮
源码库: program-in-chinese/stone-editor-eclipse 参考: FAQ How do I write an editor for my own language? D ...
- Java 由浅入深GUI编程实战练习(三)
一,項目介紹 1.可以查看年,月,日等功能.能获取今天的日期,并且能够通过下拉年,月的列表. 2.当程序运行时,显示的时间是系统当前时间. 3.可以手动输入时间,确定后系统跳转到制定的时间. 4.提供 ...
随机推荐
- 每日英语:Boost Your Balance; Avoid Falls
If you find yourself needing to sit down to take off your shoes, it might be time to start paying at ...
- dovecot--查询未读邮件个数
最近负责的邮箱系统项目中有一个这样的需求:提供一个接口给业务层,可以通过邮箱查询到该用户的未读邮件个数. 之前的方案是通过查看用户目录下.INBOX/new目录中的文件个数,但是这个方法不准确,当有用 ...
- 【转&参考】MySQL利用frm和ibd文件进行数据恢复
MySQL利用frm和idb文件进行数据恢复 源MySQL现状: 版本:5.6.* 存储引擎:innodb存储引擎 要恢复数据库:skill 重点要恢复表:slot_value 已有的文件: 备份了所 ...
- Lintcode: Implement Queue by Stacks 解题报告
Implement Queue by Stacks 原题链接 : http://lintcode.com/zh-cn/problem/implement-queue-by-stacks/# As th ...
- Java后台测试技巧
[本文出自天外归云的博客园] 问题 很多测试是和后台代码逻辑相关的,比如: 接口测试 接口文档里面包含了接口的url.用途.一些上行参数和下行参数的描述信息. 但是要想知道这些参数取值的来龙去脉,还是 ...
- Linux LVM 总结
LVM全称是Logical Volume Manager. 它主要是实现硬盘容量的动态扩展. 一般用于存储数据量无法预估的场景, 例如Linux的根目录用lvm存储. LVM创建过程一般是这样的 1. ...
- 字符驱动程序之——poll机制
关于这个韦老师给了一个简单的参考文档: poll机制分析 韦东山 2009.12.10 所有的系统调用,基本都可以在它的名字前加上“sys_”前缀,这就是它在内核中对应的函数.比如系统调用open.r ...
- Nvidia显卡安装驱动
首先要知道需要安装哪个类型的显卡驱动,可以使用如下指令查看 sudo add-apt-repository ppa:graphics-drivers在#current那一栏中找到显卡驱动型号,使用的是 ...
- 3. DNN神经网络的正则化
1. DNN神经网络的前向传播(FeedForward) 2. DNN神经网络的反向更新(BP) 3. DNN神经网络的正则化 1. 前言 和普通的机器学习算法一样,DNN也会遇到过拟合的问题,需要考 ...
- [转]oracle在删除表\表空间\用户时,如何释放磁盘空间
一.drop表 执行drop table xx 语句 drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 通过查询回收站 ...