试一下updateUI()
每个组件都有这个方法

解决方案 »

  1.   

    好象你每次点击树结点之后取数据之前没有先关闭一下DataSet再打开,或者你应该取数据之后刷新DataSet!
      

  2.   

    不可能!还是找个简单的例子看看,要不就看jdk的demo
      

  3.   

    给你一个 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;
        }
    }