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.提供 ...
随机推荐
- CentOS下使用crontab+mysqldump实现定时自动备份数据库
一 : 为什么要进行数据库的备份? 最主要的原因:尽可能地减少损失,包括时间上.精神上和金钱上的损失.很多人都不注意备份数据,以致在发生问题后丢失大量的重要数据.要知道,在地球上网是很危险的,即使做好 ...
- spring 事务传播行为实例分析
Spring事务传播行为: spring特有的事务传播行为,spring支持7种事务传播行为,确定客户端和被调用端的事务边界(说得通俗一点就是多个具有事务控制的service的相互调用时所形成的复杂的 ...
- android 修改listview item view 的方法
具体的解答办法很简单: 代码如下 : 1.获取需要更新的view int visiblePosition = mListView.getFirstVisiblePosition(); View vie ...
- TortoiseSVN checkout 之后图标(绿色勾之类的)没有显示出来的问题
http://blog.csdn.net/xigu_233/article/details/44595547 ********************************************* ...
- 【Python】微博自动抢红包
# -*- coding: utf-8 -*- import requests import js2xml from lxml import etree headers = { # 这边cookie替 ...
- 【机器学习】Softmax 和Logistic Regression回归Sigmod
二分类问题Sigmod 在 logistic 回归中,我们的训练集由 个已标记的样本构成: ,其中输入特征.(我们对符号的约定如下:特征向量 的维度为 ,其中 对应截距项 .) 由于 logis ...
- idea 同project添加多个module maven支持
选中新项目的pom.xml 会识别maven项目
- tensorboard简单使用
代码写的再好,没有图别人也不知道好在哪. 我们在使用tensorflow的时候,使用tensorboard可以直观的看到我们的网络结构,甚至它可以计算卷积和池化的维度(我不知道是不是因为我已经运行了一 ...
- 【C++程序员学 python】python 的文件类型
python的文件类型主要分为3种,分别是源代码.字节代码和优化代码.这些代码都可以直接运行,不需要进行编译或者连接.这正是python语言的特性,python的文件通过python.exe 或pyt ...
- BAT-显示桌面图标
echo offecho 显示用户的文件REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons ...