给你一个树加节点的方法。
public void AddTreeNode(Object NewNode)
{
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(NewNode.toString());
newNode.setAllowsChildren(true); //这个节点是否允许有子节点
TreePath _path = getSelectionPath();
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) _path.getLastPathComponent();
DefaultTreeModel treeModel = (DefaultTreeModel) getModel();
treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount()); // parentNode给根节点就可以了
this.scrollPathToVisible(new TreePath(newNode.getPath()));
}*****************************************
欢迎提供技术资料
http://www2.opensource.com.cn/
*****************************************
public void AddTreeNode(Object NewNode)
{
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(NewNode.toString());
newNode.setAllowsChildren(true); //这个节点是否允许有子节点
TreePath _path = getSelectionPath();
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) _path.getLastPathComponent();
DefaultTreeModel treeModel = (DefaultTreeModel) getModel();
treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount()); // parentNode给根节点就可以了
this.scrollPathToVisible(new TreePath(newNode.getPath()));
}*****************************************
欢迎提供技术资料
http://www2.opensource.com.cn/
*****************************************
private ArrayList listReqView = new ArrayList(); private class MyTableModel
extends AbstractTableModel {
private String[] columnName = new String[] {"col1", col2};
public int getRowCount() {
return listReqView.size();
} public int getColumnCount() {
return columnName.length;
} public String getColumnName(int columnIndex) {
return columnName[columnIndex];
} public Object getValueAt(int rowIndex, int columnIndex) {
DrawingOutputReq req = (DrawingOutputReq)listReqView.get(rowIndex);
if (req == null)
return null;
if (columnIndex == 0)
return new Integer(req.getReqID());
else if (columnIndex == 1)
return req.getItemNum();
return null;
}
}
JTable jtableReqs = new JTable();
jtableReqs.setModel(new MyTableModel());
上面的DrawingOutputReq是我另外的一个类.你要换成你自己的.或者数组都可以.