代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
在选中某一单元格时出现渐入效果
作者:
DDT
/ 发布于
2012/6/12
/
448
在选中某一单元格时出现渐入效果
import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.util.*; public class AnimatedJList extends JList implements ListSelectionListener {</div> <div> static java.util.Random rand = new java.util.Random();</div> <div> static Color listForeground, listBackground, listSelectionForeground, listSelectionBackground; static float[] foregroundComps, backgroundComps, foregroundSelectionComps, backgroundSelectionComps;</div> <div> static { UIDefaults uid = UIManager.getLookAndFeel().getDefaults(); listForeground = uid.getColor ("List.foreground"); listBackground = uid.getColor ("List.background"); listSelectionForeground = uid.getColor ("List.selectionForeground"); listSelectionBackground = uid.getColor ("List.selectionBackground"); foregroundComps = listForeground.getRGBColorComponents(null); foregroundSelectionComps = listSelectionForeground.getRGBColorComponents(null); backgroundComps = listBackground.getRGBColorComponents(null); backgroundSelectionComps = listSelectionBackground.getRGBColorComponents(null); } public Color colorizedSelectionForeground, colorizedSelectionBackground;</div> <div> public static final int ANIMATION_DURATION = 1000; public static final int ANIMATION_REFRESH = 50; public AnimatedJList() { super(); addListSelectionListener (this); setCellRenderer (new AnimatedCellRenderer()); } <div> public void valueChanged (ListSelectionEvent lse) { if (! lse.getValueIsAdjusting()) { HashSet selections = new HashSet(); for (int i=0; i < getModel().getSize(); i++) { if (getSelectionModel().isSelectedIndex(i)) selections.add (new Integer(i)); } CellAnimator animator = new CellAnimator (selections.toArray()); animator.start(); } } public static void main (String[] args) { JList list = new AnimatedJList (); DefaultListModel defModel = new DefaultListModel(); list.setModel (defModel); String[] listItems = { "Chris", "Joshua", "Daniel", "Michael", "Don", "Kimi", "Kelly", "Keagan" }; Iterator it = Arrays.asList(listItems).iterator(); while (it.hasNext()) defModel.addElement (it.next()); // show list JScrollPane scroller = new JScrollPane (list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JFrame frame = new JFrame ("Checkbox JList"); frame.getContentPane().add (scroller); frame.pack(); frame.setVisible(true); } <div>class CellAnimator extends Thread { Object[] selections; long startTime; long stopTime; public CellAnimator (Object[] s) { selections = s; } public void run() { startTime = System.currentTimeMillis(); stopTime = startTime + ANIMATION_DURATION; while (System.currentTimeMillis() < stopTime) { colorizeSelections(); repaint(); try { Thread.sleep (ANIMATION_REFRESH); } catch (InterruptedException ie) {} } // one more, at 100% selected color colorizeSelections(); repaint(); } <div>public void colorizeSelections() { // calculate % completion relative to start/stop times float elapsed = (float) (System.currentTimeMillis() - startTime); float completeness = Math.min ((elapsed/ANIMATION_DURATION), 1.0f); // calculate scaled color float colorizedForeComps[] = new float[3]; float colorizedBackComps[] = new float[3]; for (int i=0; i<3; i++) { colorizedForeComps[i] = foregroundComps[i] + (completeness * (foregroundSelectionComps[i] - foregroundComps[i])); colorizedBackComps[i] = backgroundComps[i] + (completeness * (backgroundSelectionComps[i] - backgroundComps[i])); } colorizedSelectionForeground = new Color (colorizedForeComps[0], colorizedForeComps[1], colorizedForeComps[2]);</div> <div> colorizedSelectionBackground = new Color (colorizedBackComps[0], colorizedBackComps[1], colorizedBackComps[2]); } <div> class AnimatedCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus) { Component returnMe = super.getListCellRendererComponent (list, value, index, isSelected, hasFocus); if (isSelected) { returnMe.setForeground (colorizedSelectionForeground); returnMe.setBackground (colorizedSelectionBackground); /* this might be necessary if you have more elaborate cells if (returnMe instanceof Container) { Component[] children = ((Container)returnMe).getComponents (); System.out.println (children.length + " children"); for (int i=0; (children != null ) && (i<children.length); i++) { children[i].setForeground (colorizedSelectionForeground); children[i].setBackground (colorizedSelectionBackground); } } */ if (returnMe instanceof JComponent) ((JComponent) returnMe).setOpaque(true); } return returnMe; } } <div>} </div>
试试其它关键字
渐入效果
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
实现测量程序运行时间及cpu使用时间
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
DDT
贡献的其它代码
(
160
)
.
Oracle统计表的数据行和数据块信息
.
html标签闭合检测与修复
.
Powershell日期计算
.
Powershell的Base64编解码
.
Powershell并行循环
.
Powershell目录中搜索文本
.
Powershell枚举远程机器上的本地权限组
.
VBScript解析csv文件
.
快速排序之Powershell
.
批处理输出格式化时间字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3