一天了,帖子发了四五回,还是没解决!(我的分已经用完了) 试一下updateUI()每个组件都有这个方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好象你每次点击树结点之后取数据之前没有先关闭一下DataSet再打开,或者你应该取数据之后刷新DataSet! 不可能!还是找个简单的例子看看,要不就看jdk的demo 给你一个 TableModel 的例子package com.iaworld.oa.sysadmin.components.table;import org.apache.commons.beanutils.PropertyUtils;import javax.swing.table.AbstractTableModel;import java.util.List;import java.util.ArrayList;import java.beans.PropertyDescriptor;/** * 用于显示 JavaBeans 集合的表格数据模型.<p> */public class BeanTableModel extends AbstractTableModel{ //JavaBeans 类 private Class beanClass; //属性描述者 private PropertyDescriptor[] pds; private List beans; private boolean editable = false; /** * 构造函数 * @param beanClass JavaBeans 类 */ public BeanTableModel(Class beanClass) { if(beanClass == null) throw new IllegalArgumentException("Parameter [beanClass] not allow null"); this.beanClass = beanClass; beans = new ArrayList(); pds = PropertyUtils.getPropertyDescriptors(this.beanClass); } /** * 构造函数 * @param beanClass beanClass JavaBeans 类 * @param beans 需显示的 Beans 集合 */ public BeanTableModel(Class beanClass, List beans) { if(beanClass == null) throw new IllegalArgumentException("Parameter [beanClass] not allow null"); if(beans == null) throw new IllegalArgumentException("Parameter [beans] not allow null"); this.beanClass = beanClass; this.beans = beans; pds = PropertyUtils.getPropertyDescriptors(this.beanClass); } public int getRowCount() { return beans.size(); } public String getColumnName(int column) { return pds[column].getName(); } public int getColumnCount() { return pds.length; } public Object getValueAt(int rowIndex, int columnIndex) { Object obj = beans.get(rowIndex); PropertyDescriptor pd = pds[columnIndex]; try { return PropertyUtils.getSimpleProperty(obj, pd.getName()); } catch (Exception e) { return null; } } public Class getColumnClass(int columnIndex) { return pds[columnIndex].getPropertyType(); } public boolean isCellEditable(int rowIndex, int columnIndex) { if(!editable) return false; return pds[columnIndex].getWriteMethod() != null; } public void setValueAt(Object aValue, int rowIndex, int columnIndex) { Object obj = beans.get(rowIndex); PropertyDescriptor pd = pds[columnIndex]; try { PropertyUtils.setSimpleProperty(obj, pd.getName(), aValue); } catch (Exception e) { //忽略 //TODO:记录日志 } } /** * 设置新的表格数据 * @param beans JavaBeans 集合 */ public void setBeans(List beans) { this.beans = beans; fireTableDataChanged(); } /** * 得到指定行的对象 * @param rowIndex 指定行 * @return 指定行的 JavaBeans 对象 */ public Object rowAt(int rowIndex) { return beans.get(rowIndex); } /** * 更新指定行的对象 * @param rowIndex 指定行 * @param bean 新对象 */ public void updateRow(int rowIndex, Object bean) { beans.set(rowIndex, bean); fireTableRowsUpdated(rowIndex, rowIndex); } /** * 新增一行对象 * @param bean 新对象 */ public void addRow(Object bean) { beans.add(bean); fireTableRowsInserted(beans.size() - 1, beans.size() - 1); } /** * 插入一行对象 * @param rowIndex 指定行 * @param bean 新对象 */ public void insertRow(int rowIndex, Object bean) { beans.add(rowIndex, bean); fireTableRowsInserted(rowIndex, rowIndex); } /** * 删除一行数对象 * @param rowIndex */ public void deleteRow(int rowIndex) { beans.remove(rowIndex); fireTableRowsDeleted(rowIndex, rowIndex); } /** * 获取指定对象的行索引 * @param bean 指定对象 * @return 行索引 */ public int indexOf(Object bean) { return beans.indexOf(bean); } /** * 获取表格模型是否可修改 * @return */ public boolean isEditable() { return editable; } /** * 设置表格模型是否可修改 * @param editable */ public void setEditable(boolean editable) { this.editable = editable; } /** * 获取所有对象 * @return 所有对象 */ public List getBeans() { return beans; }} 如何打印2是n次方的集合 江湖救急啊!!刚编了个简单的Java程序 不知道为什么出错 大家看下啊 A为什么不对,F为什么对? 请教数组问题 求助,java的一个小问题 奇怪问题!!!!求高手解答!!! 线程的理解! 多行文字TextArea的问题 我按照网上介绍的文章配置了Apache1.3+Tomcat4.0,却有一点小问题,敬请高手指点!谢谢! java client端实现技术方案,求救! 难道就没有知道怎样把eclipse的swt转成swing 一个奇怪的问题:为什么应用程序关闭后还有javaw.exe?
import java.util.List;
import java.util.ArrayList;
import java.beans.PropertyDescriptor;/**
* 用于显示 JavaBeans 集合的表格数据模型.<p>
*/
public class BeanTableModel
extends AbstractTableModel
{ //JavaBeans 类
private Class beanClass; //属性描述者
private PropertyDescriptor[] pds; private List beans; private boolean editable = false; /**
* 构造函数
* @param beanClass JavaBeans 类
*/
public BeanTableModel(Class beanClass)
{
if(beanClass == null) throw new IllegalArgumentException("Parameter [beanClass] not allow null"); this.beanClass = beanClass;
beans = new ArrayList(); pds = PropertyUtils.getPropertyDescriptors(this.beanClass);
} /**
* 构造函数
* @param beanClass beanClass JavaBeans 类
* @param beans 需显示的 Beans 集合
*/
public BeanTableModel(Class beanClass, List beans)
{
if(beanClass == null) throw new IllegalArgumentException("Parameter [beanClass] not allow null");
if(beans == null) throw new IllegalArgumentException("Parameter [beans] not allow null"); this.beanClass = beanClass;
this.beans = beans;
pds = PropertyUtils.getPropertyDescriptors(this.beanClass);
} public int getRowCount()
{
return beans.size();
} public String getColumnName(int column)
{
return pds[column].getName();
} public int getColumnCount()
{
return pds.length;
} public Object getValueAt(int rowIndex, int columnIndex)
{
Object obj = beans.get(rowIndex);
PropertyDescriptor pd = pds[columnIndex];
try
{
return PropertyUtils.getSimpleProperty(obj, pd.getName());
}
catch (Exception e)
{
return null;
}
} public Class getColumnClass(int columnIndex)
{
return pds[columnIndex].getPropertyType();
} public boolean isCellEditable(int rowIndex, int columnIndex)
{
if(!editable) return false;
return pds[columnIndex].getWriteMethod() != null;
} public void setValueAt(Object aValue, int rowIndex, int columnIndex)
{ Object obj = beans.get(rowIndex);
PropertyDescriptor pd = pds[columnIndex];
try
{
PropertyUtils.setSimpleProperty(obj, pd.getName(), aValue);
}
catch (Exception e)
{
//忽略
//TODO:记录日志
}
} /**
* 设置新的表格数据
* @param beans JavaBeans 集合
*/
public void setBeans(List beans)
{
this.beans = beans;
fireTableDataChanged();
} /**
* 得到指定行的对象
* @param rowIndex 指定行
* @return 指定行的 JavaBeans 对象
*/
public Object rowAt(int rowIndex)
{
return beans.get(rowIndex);
} /**
* 更新指定行的对象
* @param rowIndex 指定行
* @param bean 新对象
*/
public void updateRow(int rowIndex, Object bean)
{
beans.set(rowIndex, bean);
fireTableRowsUpdated(rowIndex, rowIndex);
} /**
* 新增一行对象
* @param bean 新对象
*/
public void addRow(Object bean)
{
beans.add(bean);
fireTableRowsInserted(beans.size() - 1, beans.size() - 1);
} /**
* 插入一行对象
* @param rowIndex 指定行
* @param bean 新对象
*/
public void insertRow(int rowIndex, Object bean)
{
beans.add(rowIndex, bean);
fireTableRowsInserted(rowIndex, rowIndex);
} /**
* 删除一行数对象
* @param rowIndex
*/
public void deleteRow(int rowIndex)
{
beans.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
} /**
* 获取指定对象的行索引
* @param bean 指定对象
* @return 行索引
*/
public int indexOf(Object bean)
{
return beans.indexOf(bean);
} /**
* 获取表格模型是否可修改
* @return
*/
public boolean isEditable()
{
return editable;
} /**
* 设置表格模型是否可修改
* @param editable
*/
public void setEditable(boolean editable)
{
this.editable = editable;
}
/**
* 获取所有对象
* @return 所有对象
*/
public List getBeans()
{
return beans;
}
}