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.提供 ...
随机推荐
- Linux系统/boot目录破损无法启动怎么办
linux系统中的/boot目录存放着系统开机所需要的各种文件,其中包含内核.开机菜单及所需配置文件等等.但是当不小心删除了/boot目录里的某些文件或者干脆整个/boot目录都不见了的情况下,该如何 ...
- [Windows Azure] About Affinity Groups for Virtual Network
Affinity groups are the way to group the services in your Windows Azure subscription that need to wo ...
- CORS跨域、Cookie传递SessionID实现单点登录后的权限认证的移动端兼容性测试报告
简述 本文仅记录如标题所述场景的测试所得,由于场景有些特殊,且并不需兼容所有浏览器,所以本文的内容对读者也许并无作用,仅为记录. 场景.与实现 需在移动端单点登录 需在移动端跨域访问我们的服务 基于历 ...
- (转)使用异步Python 3.6和Redis编写快速应用程序
转自:http://mp.weixin.qq.com/s?__biz=MjM5NzU0MzU0Nw==&mid=2651374524&idx=1&sn=d289aa7aa484 ...
- 【驱动】linux设备驱动·字符设备驱动开发
Preface 前面对linux设备驱动的相应知识点进行了总结,现在进入实践阶段! <linux设备驱动入门篇>:http://infohacker.blog.51cto.com/6751 ...
- 使用httpclient下载 页面、图片
代码 import java.io.IOException; import java.io.UnsupportedEncodingException; import org.apache.http.c ...
- python 使用pillow将图片转换为webp格式
1.webp格式 webp格式是谷歌开发的一种旨在加快图片加载速度的格式,将图片转为webp格式后,体积约为原来的2/3,这可以节省大量的服务器带宽,微信公众号文章里的图片就是这种格式的. 2.使用p ...
- 在windows下nginx+django+flup python3
1.安装python 下载最新的python版本,在本文撰写时为 python 3.4, 下载地址:https://www.python.org/ftp/python/3.4.0/python-3.4 ...
- Python基本语法_强制数据类型转换
目录 目录 前言 软件环境 Python数据类型的显式转换 显式转换的多种类型 Non-String转换为String str函数 repr str和repr的区别 eval Non-int转换为in ...
- 3. sklearn的K-Means的使用
1. K-Means原理解析 2. K-Means的优化 3. sklearn的K-Means的使用 4. K-Means和K-Means++实现 1. 前言 在机器学习中有几个重要的python学习 ...