向JTable中加入单元编辑器 http://www2.gol.com/users/tame/swing/examples/JTableExamples2.html看each row editor 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 the default editor of JTable is JLabel.I think you can set the editor is JComponent.then you set editor for every row 我恰好这样子做过:)基本思路就是实现TableCellEditor接口,自己写一个实现类。最重要的方法就是重载public abstract Component getTableCellEditorComponent (JTable table, Object value, boolean isSelected, int row,int col)你可以通过row或者value的不同来返回自己需要的Component作为该单元或者该value的编辑器。用同样的办法,你最好把Table的Renderer也自己写一下。保证为每种不同的对象有确切的绘制器。比如:if (row ==2){ JCheckBox cbkEditor = new JCheckBox(); Boolean b = (Boolean)value;//假定这一行是一个Boolean类型 cbkEditor.setSelected(b.boolValue()); return cbkEditor;}else{ JComboBox enumEditor = new JComboBox(); enmuEidtor.addItem("A"); ... return enumEditor;} java中 如何用命令删除数据库中的所有表 JAVA中的多继承问题 怎样在JTable中删除所有的行 用java递归求一个平均数多少种可能的算法 请教关于线程的问题 dsa 在eclipse中怎么运行带参数的程序? 调用cloneable接口时遇到的奇怪的错误 weblogic?????????? 以前写的没错的,不知道今天怎么错了,请帮看看… 对stub没理解透 怎样把System.currentTimeMillis()换算成可以正确识别的时间?
I think you can set the editor is JComponent.
then you set editor for every row
public abstract Component getTableCellEditorComponent (JTable table,
Object value,
boolean isSelected,
int row,int col)
你可以通过row或者value的不同来返回自己需要的Component作为该单元或者该value的编辑器。用同样的办法,你最好把Table的Renderer也自己写一下。保证为每种不同的对象有确切的绘制器。
比如:
if (row ==2){
JCheckBox cbkEditor = new JCheckBox();
Boolean b = (Boolean)value;//假定这一行是一个Boolean类型
cbkEditor.setSelected(b.boolValue());
return cbkEditor;
}
else{
JComboBox enumEditor = new JComboBox();
enmuEidtor.addItem("A");
...
return enumEditor;
}