我想让在满足一定条件的情况下才能选中树中节点,在条件不满足时,不允许在树中选节点,不知如何来实现?
解决方案 »
- 编写坦克大战代码时出现void is an invalid type for the variable drawTank
- ACER待机问题!!!!!!
- java连接sql server2000
- 怎么 :Cannot create PoolableConnectionFactory
- javax.mail.AuthenticationFailedException:EOF on socket
- 小弟的程序又出问题了,敢请高手赐教
- 在JAVA中能否象Delphi一样在参数前加一个Var,将值传回来!
- 请教,java的socket编程用的多不多
- how change String "yyyy-mm-dd" to java.sql.date
- 散分!给所有热心的朋友。。。。。
- servlet 问题! 在线等!!
- 新建的Frame能关闭?super(str)起什么作用?
class testMouseAdapter
extends MouseAdapter {
public MetaTreeListener() {
metaTree = tree;
} public void mouseReleased(MouseEvent e) {
//右击事件
if (e.getButton() == 3) { }
} public void mouseClicked(MouseEvent e) {
//左击事件
if (e.getButton() == 1) {
//双击事件
if (e.getClickCount() == 2) { }
//单击事件
else if (e.getClickCount() == 1) { }
}
} }
不好意思,没说明白,我的题目写的意思点击JTree节点后到节点没有被选中时发生的事件,
想人为阻止节点被选中。
现在用另一种方法代替了,
通过监听TreeSelectionEvent和保存/恢复原选中节点TreePath[]实现。
3x
先存被选中所有节点的TreePath[]
然后在public void valueChanged(TreeSelectionEvent e)中用
JTree.setSelectionPaths(TreePath[]);恢复