Initial project
This commit is contained in:
45
src/main/java/com/imyeyu/fx/ui/components/XTreeView.java
Normal file
45
src/main/java/com/imyeyu/fx/ui/components/XTreeView.java
Normal file
@ -0,0 +1,45 @@
|
||||
package com.imyeyu.fx.ui.components;
|
||||
|
||||
import com.imyeyu.fx.utils.SmoothScroll;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.scene.control.TreeView;
|
||||
|
||||
/**
|
||||
* 不显示根节点的树形结构,实现多个根节点
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2021-04-26 01:34
|
||||
*/
|
||||
public class XTreeView<T> extends TreeView<T> {
|
||||
|
||||
private final TreeItem<T> dummyRoot = new TreeItem<>();
|
||||
|
||||
/** 默认构造 */
|
||||
public XTreeView() {
|
||||
dummyRoot.setExpanded(true);
|
||||
setRoot(dummyRoot);
|
||||
setShowRoot(false);
|
||||
// 平滑滚动
|
||||
SmoothScroll.virtual(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置根节点
|
||||
*
|
||||
* @param roots 根节点
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final void setRoots(TreeItem<T>... roots) {
|
||||
dummyRoot.getChildren().addAll(roots);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取根节点列表
|
||||
*
|
||||
* @return 根节点列表
|
||||
*/
|
||||
public ObservableList<TreeItem<T>> getRoots() {
|
||||
return dummyRoot.getChildren();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user