Java Code Examples for javax.swing.JTree#addTreeExpansionListener()

The following examples show how to use javax.swing.JTree#addTreeExpansionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Viewer.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
public void init() throws TableNotFoundException {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode(
      new NodeInfo(topPath, q.getData(topPath)));
  populate(root);
  populateChildren(root);

  treeModel = new DefaultTreeModel(root);
  tree = new JTree(treeModel);
  tree.addTreeExpansionListener(this);
  tree.addTreeSelectionListener(this);
  text = new JTextArea(getText(q.getData(topPath)));
  data = new JTextArea("");
  JScrollPane treePane = new JScrollPane(tree);
  JScrollPane textPane = new JScrollPane(text);
  dataPane = new JScrollPane(data);
  JSplitPane infoSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textPane, dataPane);
  JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePane, infoSplitPane);
  mainSplitPane.setDividerLocation(300);
  infoSplitPane.setDividerLocation(150);
  getContentPane().add(mainSplitPane, BorderLayout.CENTER);
}
 
Example 2
Source File: SelectSettlersFolderDialog.java    From settlers-remake with MIT License 6 votes vote down vote up
/**
 * Initialize the Tree with the filesystem
 */
private void initTree() {
	RootTreeNode root = new RootTreeNode(executorService);

	for (File f : File.listRoots()) {
		root.add(new FilesystemTreeNode(f));
	}

	model = new DefaultTreeModel(root);

	// to fire change event when the loading is finished
	root.setModel(model);
	tree = new JTree(model);

	tree.addTreeSelectionListener(selectionListener);
	tree.addTreeExpansionListener(expansionListener);
	tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	tree.expandRow(0);
	tree.setRootVisible(false);
	tree.setCellRenderer(new FileTreeCellRenderer());
}
 
Example 3
Source File: ManagementModel.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private JTree makeTree(ManagementModelNode root) {
    root.explore();
    JTree tree = new CommandBuilderTree(cliGuiCtx, new DefaultTreeModel(root));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeExpansionListener(new ManagementTreeExpansionListener((DefaultTreeModel) tree.getModel()));
    tree.addTreeSelectionListener(new ManagementTreeSelectionListener());
    tree.addMouseListener(new ManagementTreeMouseListener(tree));
    return tree;
}
 
Example 4
Source File: WindowsDirectoryChooserUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public void installComponents(JFileChooser chooser) {
  this.chooser = (JDirectoryChooser)chooser;

  chooser.setLayout(LookAndFeelTweaks.createBorderLayout());
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

  Component accessory = chooser.getAccessory();
  if (accessory != null) {
    chooser.add("North", chooser.getAccessory());
  }

  tree = new JTree() {
    public String getToolTipText(MouseEvent event) {
      String tip = WindowsDirectoryChooserUI.this.getToolTipText(event);
      if (tip == null) {
        return super.getToolTipText(event);
      } else {
        return tip;
      }
    }
  };
  tree.addTreeExpansionListener(new TreeExpansion());

  tree.setModel(new FileSystemTreeModel(chooser.getFileSystemView()));
  tree.setRootVisible(false);
  tree.setShowsRootHandles(false);
  tree.setCellRenderer(new FileSystemTreeRenderer());
  tree.setToolTipText("");

  chooser.add("Center", treeScroll = new JScrollPane(tree));
  treeScroll.setPreferredSize(new Dimension(300, 300));

  approveButton = new JButton();
  approveButton.setAction(getApproveSelectionAction());

  cancelButton = new JButton();
  cancelButton.addActionListener(getCancelSelectionAction());

  buttonPanel = new JPanel(LookAndFeelTweaks.createButtonAreaLayout());
  buttonPanel.add(approveButton);
  buttonPanel.add(cancelButton);
  chooser.add("South", buttonPanel);

  updateView(chooser);
}
 
Example 5
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructor
 * @param tree
 */
TreeTableModelAdapter(JTree tree)
{
	this.tree = tree;
	tree.addTreeExpansionListener(this);
}
 
Example 6
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructor
 * @param tree
 */
TreeTableModelAdapter(JTree tree)
{
	this.tree = tree;
	tree.addTreeExpansionListener(this);
}