感觉这样加是不行的吧,数据操作肯定要再treemodel里面吧
解决方案 »
- 如何在JTree中将"我的电脑"设置成根目录
- 我做的一个作业,请问还有没有更好的程序
- 求一段代码:咋样判断字符一个串对象是null的或该字符串完全是由空格组成的
- 邮件地址的正则表达式
- Java 中 的 org.jconfig.ConfigurationManager 问题
- ☆没人知道啊..☆,..在框架中又new一个框架..!高手都挂了吗 高分!!
- 各位帮一下忙,一个关于用bat文件来启动JAVA程序的问题
- jacob 打开excel问题
- 请问如何限制在JTextField中允许输入的最大字符数?
- java quartz框架 第一次执行时间会延迟
- int型怎么转换为byte型?
- 如何实现JTree在不同的子叶的情况下,显示不同的图标形式?
DefaultTreeModel model = jTree1.getModel();
model.insertNodeInto();
//insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
TreeSelectionModel sm = jTree1.getSelectionModel();
sm.addSelectionPath(new TreePath(new String("JTree, food, pizza")));是对已存在的节点的选取啊!
TreePath[] tps = jTree1.getSelectionPaths();
TreeSelectionModel sm = jTree1.getSelectionModel();
sm.addSelectionPath(new TreePath(new String("JTree, food, pizza")));
~~~~~~~~~~~~~`~~~~~~~~~~~~~~~~~~~~~~~~~~`
这是新的treepath,不是已经有的treepath,所以你设置
选中的东西部可能在树上显示出来,明白不?
呵呵。收分罗
tree.setSelectionPath(path);
path 为输入路径
cellRenderer.setBackgroundNonSelectionColor(Color.white);
cellRenderer.setBackgroundSelectionColor(Color.yellow);
cellRenderer.setBorderSelectionColor(Color.red);
cellRenderer.setTextNonSelectionColor(Color.black);
cellRenderer.setTextSelectionColor(Color.blue);