public class mainFrame2 extends javax.swing.JFrame
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("文件列表");
private DefaultTreeModel dt = new DefaultTreeModel(root);
public mainFrame2()
{
jTree1.setRowHeight(25);
showTree();
}
private void initComponents()
{
jTree1 = new javax.swing.JTree(root);
...
pack();
}
/*
* 填充JTree
*/
public void showTree()
{
conn myconn = new conn();
ResultSet nodeRs;
ResultSet leafRs;
if (root.isLeaf() == false)
root.removeAllChildren();
try
{
nodeRs = myconn.queryDB("select distinct cType from tempDocFiles where position='" + this.position + "'");
leafRs = myconn.queryDB("select cType,fileName from tempDocFiles where position='" + this.position + "'");
if (!nodeRs.next())
{
JOptionPane.showMessageDialog(this, "当前没有上传文件记录,请先上传文件!");
} else
{
nodeRs.beforeFirst();//将第1组数据的游标移到第一条记录之前
while (nodeRs.next())
{
DefaultMu
swing jTree 节点刷新,默认全部展开
最新推荐文章于 2025-06-16 21:21:11 发布