社区
Java SE
帖子详情
如何设置JTable某一个cell的Renderer
colorfish
2004-03-29 11:11:11
我知道table.getColumn("字段").setCellRenderer(new ButtonRenderer())可以设置某一列的Renderer
但如何设置JTable某一个cell的Renderer
...全文
122
4
打赏
收藏
如何设置JTable某一个cell的Renderer
我知道table.getColumn("字段").setCellRenderer(new ButtonRenderer())可以设置某一列的Renderer 但如何设置JTable某一个cell的Renderer
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
onefox
2004-04-18
打赏
举报
回复
http://www.javaresearch.org/article/showarticle.jsp?column=331&thread=8684
看中间那段
ac669
2004-04-18
打赏
举报
回复
不明白!!!!! :)
我也正碰到这个问题.
我想改变某个单元格的颜色该怎么做???
Leemaasn
2004-03-29
打赏
举报
回复
不明白。。
先Up
cqandy
2004-03-29
打赏
举报
回复
给你个例子:
thisRenderer = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected,
boolean hasFocus, int row,
int column)
{
if (column ==0){File thisfile=new File(((File)value).getName());
return super.getTableCellRendererComponent(table, (File)thisfile, isSelected,
hasFocus, row,
column);
}
else
{
JButton bn=new JButton("button");
return bn;
}}
使用 AbstractTableModel 构建Table 在表格中添加JButton按钮
使用 AbstractTableModel 构建Table 在表格中添加JButton按钮,之前在网上找了2天没有找到好用的程序,最终终于找到
一个
好用的例子。 不要使,我退你们分。。 sing the Swing
JTable
class can quickly become a sticky business when you want to customize it to your specific needs. First you must become familiar with how the
JTable
class is organized. Individual
cell
s are rendered by Table
Cell
Renderer
implementations. The table contents are represented by an implementation of the TableModel interface. By default,
JTable
uses DefaultTable
Cell
Renderer
to draw its
cell
s. DefaultTable
Cell
Renderer
recognizes a few primitive types, rendering them as strings, and can even display Boolean types as checkboxes. But it defaults to displaying the value returned by toString() for types it does not specifically handle. You have to provide your own Table
Cell
Renderer
implementation if you want to display buttons in a
JTable
. The Table
Cell
Renderer
interface contains only one method, getTable
Cell
Renderer
Component(...), which returns a java.awt.Component that knows how to draw the contents of a specific
cell
. Usually, getTable
Cell
Renderer
Component() will return the same component for every
cell
of a column, to avoid the unnecessary use of extra memory. But when the contents of a
cell
is itself a component, it is all right to return that component as the
renderer
. Therefore, the first step towards having JButtons display correctly in a
JTable
is to create a Table
Cell
Renderer
implementation that returns the JButton contained in the
cell
being rendered. In the accompanying code listing,
JTable
Button
Renderer
demonstrates how to do this. Even after creating a custom Table
Cell
Renderer
, you're still not done. The TableModel associated with a given
JTable
does not only keep track of the contents of each
cell
, but it also keeps track of the class of data stored in each column. DefaultTableModel is designed to work with DefaultTable
Cell
Renderer
and will return java.lang.String.class for columns containing data types that it does not specifically handle. The exact method that does this is getColumnClass(int column). Your second step is to create a TableModel implementation that returns JButton.class for
cell
s that contain JButtons.
JTable
ButtonModel shows one way to do this. It just returns the result of getClass() for each piece of
cell
data. At this point, you're almost done, but not quite. What's the use of putting a JButton in a
JTable
if you can't press the darn thing? By default,
JTable
will not forward mouse events to components contained in its
cell
s. If you want to be able to press the buttons you add to
JTable
, you have to create your own MouseListener that forwards events to the JButton
cell
s.
JTable
ButtonMouseListener demonstrates how you could do this.
xpTable,c# xptable NET中最强,最全功能的表格控件 ,可以定制
一个
ListView,能够在列中插入图像、下拉框、可上下调整的数字、进度条
c# xptable NET中最强,最全功能的表格控件 可以定制
一个
ListView,能够在列中插入图像、下拉框、可上下调整的数字、进度条等等。 [功能] 全定制可视化界面 支持XP风格 轻易添加再定制的控件 可隐藏列 行、列、单元可以被Disable 每个单元、列可以有Tooltip 等等…… [XPTable] XPTable包含下面的组件: 1. Table, 2. ColumnModel 和它的 Columns, 3. TableModel 和它的 Row 和
Cell
, 4.
Renderer
5. Editor [翻译] Mathew Hall.著XPTable - .NET ListView meets Java's
JTable
[简介] 由于项目需要,我需要定制
一个
ListView,它必须能够在列中插入图像、下拉框、可上下调整的数字、进度条等等。由于已经有了
一个
Java下的背景,我将简单地基于那个
JTable
封装。 [功能] 全定制可视化界面 支持XP风格 轻易添加再定制的控件 可隐藏列 行、列、单元可以被Disable 每个单元、列可以有Tooltip 等等…… [XPTable] XPTable包含下面的组件: 1. Table, 2. ColumnModel 和它的 Columns, 3. TableModel 和它的 Row 和
Cell
, 4.
Renderer
5. Editor [控件使用] 首先加载控件到Toolbox上(添加
一个
Item,引用XPTable.dll) 然后,拖动Table, ColumnModel 和 TableModel到Form上,
设置
Table的ColumnModel 和 TableModel属性,添加Column到ColumnModel,添加Row 和
Cell
到TableModel.
JPojoTable-开源
先进的
JTable
框架-新的Swing组件(带有工具栏的
JTable
)特点:-无需编写表模型! -检查JPA bean / Pojos / Javabeans /手动配置-事务保存-可编辑属性处理程序-提供增强的
Renderer
/
Cell
编辑器
jTable
设置
单个单元格颜色
尝试Swing已经一星期,感觉Swing里的坑还是很多的,对于我这种刚入门的新手来说,接口确实有些不顺手。 闲话休提。需求是这样的,绘制
一个
数据表格,假如其中某个单元格的数据超出阈值,该单元格标红。 在Swing的库里简略地翻了一阵子的结果是,并没有找到现成的、
设置
单个单元格的接口,
设置
JTable
某个单元格的背景颜色和前景颜色
下面这个实例是
设置
表格的第一行第三格背景颜色为蓝色,前景颜色为红色。 package com.test.view; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import javax.swing.JFrame; import javax.swing.JScrol
Java SE
62,623
社区成员
307,257
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章