楼主 admin 发表于2014年9月23日 下午4:45:33
奇新Java控件集增加了一个简洁优雅的JTreeTable控件

奇新Java控件v3.5 Beta16增加了一个简洁优雅的JTreeTable控件(v3.6 Beta16新功能):


显示Checkbox


不显示Checkbox

演示代码:

public class TreeTableDemo extends JBean {
    private boolean useXtree = true;
    public TreeTableDemo() {
        this.setExtendedState(Frame.NORMAL);
        FileTreeModel m = new FileTreeModel();
        JTree tree = useXtree ? createXTree(m) : createTree(m);
        // since FileTableModel implements JTreeTable.ModelHelper
        JTreeTable table = new JTreeTable(tree, new FileTableModel(), 5);
        add(new JScrollPane(table), BorderLayout.CENTER);
    }
    public static void main(String[] args) {
        TreeTableDemo demo = new TreeTableDemo();
	demo.setDefaultCloseOperation(JBean.EXIT_ON_CLOSE);        
        demo.showFrame();
    }
    private JTree createTree(TreeModel m) {
        JTree tree = new JTree(m);
        tree.setCellRenderer(new FileCellRenderer());
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        return tree;
    }
    
    private XTree createXTree(TreeModel m) {
        XTree tree = new XTree(m);
        tree.setRealCellRenderer(new FileCellRenderer());
        tree.setSelectionMode(XTree.INHERITANCE_TREE_SELECTION);
        return tree;
    }
}

可以直接将您的JTree放在JTreeTable控件中,再增加一个适配器提供数据就行了,使用普通的JTree不显示Checkbox,使用XTree可以显示Checkbox!