建议你看看java tutorial,里面关于JTable的教程有现成的例子,都是你需要的。
解决方案 »
- 网上流传的获得汉字拼音首字母的java程序有个问题
- 问一个java小程序
- 怎样将当前字符串常量转换为字符数组
- 求Jbuilder9.0哪里有下载啊!!!!!!!!!!!!!!
- 自己写了个类在1.4下编译,然后引用了这个类,但是在1.3下编译,是否能使用?
- JButton只能是长方形的,可不可是圆形,三角形或任何形状?
- 我下载了一个源程序,在源程序里面的报名已经定了,我现在想把这个源程序加到我自己的程序了,有没有什么方法批量的把这个源程序中的报名
- 对象类型可以作为变量进行强转吗?
- 超级弱智问题大比拼!!!!!!!!(强烈郁闷中************)
- HTTP 请求的一个问题
- 字符排序算法问题
- 帮我解决个小问题,谢谢大家
(new DefaultCellEditor(new JComboBox(vector对象)));
当时我的需要是在同一列中也要根据不同的情况产生不同的编辑器(有的是下拉框,有的是文本框)。你首先看你的具体需求,如果只是我说的第一种情况,用DefaultCellEditor即可,Tutorial上不是有源文件的链接吗?你可以打开,看一下,如果是跟我的情况相同,我可以给你一段代码:
我是用内部类实现的,你可以参考。
/**
* this inner class implement interface of TableCellEditor
* mainly make user select instance-value
*/
class MyDefaultTableEditor extends AbstractCellEditor implements TableCellEditor{
private JComboBox jcb_instance = null;
private JTextField jtf_instance = null;
private String propertyName = null;
//identify if property is relative,use different Get-Value-Method
private boolean isRelative = false;
public MyDefaultTableEditor(){
jcb_instance = new JComboBox();
jtf_instance = new JTextField();
}
public Object getCellEditorValue(){
Object returnVal = null;
if (isRelative){
returnVal = jcb_instance.getSelectedItem();
jcb_instance.removeAllItems();
}
else{
returnVal = jtf_instance.getText();
jtf_instance.setText("");
}
return returnVal;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column){
//get property name
propertyName = (String)jtable_instanceValue.getValueAt(row,0);
//if property is relative,find instances of specific class
SMALProperty eProperty = model.getEachProperty(propertyName);
if ( (eProperty!=null) && (eProperty.getRelative()) ){
isRelative = true;
//fill combobox data
String className = eProperty.getRange();
Object[] instances = model.getInstances(className,true);
jcb_instance.removeAllItems();
for (int i=0; i<instances.length; i++) {
jcb_instance.addItem(instances[i]);
}
return jcb_instance;
}
else{
isRelative = false;
jtf_instance.setText((String)value);
}
return jtf_instance;
}
}