Jree.getPathForRow(row) 得到的对象为空

1、问题:TreePath treePath = tree.getPathForRow(row);

得到的treePath为NULL。

 

2、原因:在MyCheckBoxTreeCellRenderer渲染类的stringvalue中,一定要是

通过String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);得到的值。

如果你仅仅是执行 tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); ,stringvalue自定义值。这样也是不行的。

我估计这里,最后要和传入的对象的.toString进行比对,比对成功后才能返回行( tree.getPathForRow(row);)

 

3、解决办法:封装一个传入节点的对象,重写toString方法就可以了

public class CustomMyCheckBoxEntity {
	private TCComponentBOMLine bomLine;
	private TCComponentItemRevision topItemRev;
	
	public CustomMyCheckBoxEntity(TCComponentBOMLine bomLine, TCComponentItemRevision topItemRev) {
		super();
		this.bomLine = bomLine;
		this.topItemRev = topItemRev;
	}

	public TCComponentBOMLine getBomLine() {
		return bomLine;
	}

	@Override
	public String toString() {
		return getDrawingNumber(topItemRev,bomLine);
	}
}

  

 

posted @ 2023-01-11 11:40  信铁寒胜  阅读(37)  评论(0编辑  收藏  举报