Example usage for javax.swing JTree setSelectionModel

List of usage examples for javax.swing JTree setSelectionModel

Introduction

In this page you can find the example usage for javax.swing JTree setSelectionModel.

Prototype

@BeanProperty(description = "The tree's selection model.")
public void setSelectionModel(TreeSelectionModel selectionModel) 

Source Link

Document

Sets the tree's selection model.

Usage

From source file:Main.java

public static void main(String[] args) {
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    fillTree(root, 5, "Tree label");
    final DefaultTreeModel model = new DefaultTreeModel(root);
    JTree tree = new JTree(model);
    tree.setSelectionModel(new MyTreeSelectionModel());
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JScrollPane(tree));
    f.setSize(400, 600);//from w  ww.j  a va  2  s.c o  m
    f.setVisible(true);
}