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

The following examples show how to use javax.swing.JTree#getSelectionModel() . 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: ProcessingComponent.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private @Nullable DefaultMutableTreeNode getSelectedItem(@Nonnull JTree tree) {
  TreeSelectionModel selectionModel = tree.getSelectionModel();
  if (selectionModel == null)
    return null;
  TreePath path = selectionModel.getSelectionPath();
  if (path == null)
    return null;
  return (DefaultMutableTreeNode) path.getLastPathComponent();
}
 
Example 2
Source File: ProcessingComponent.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private @Nullable DefaultMutableTreeNode getSelectedItem(@Nonnull JTree tree) {
  TreeSelectionModel selectionModel = tree.getSelectionModel();
  if (selectionModel == null)
    return null;
  TreePath path = selectionModel.getSelectionPath();
  if (path == null)
    return null;
  return (DefaultMutableTreeNode) path.getLastPathComponent();
}
 
Example 3
Source File: AbstractTab.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
protected void setTree (JTree tree)
// ---------------------------------------------------------------------------------//
{
  this.tree = tree;
  tree.setFont (font);
  scrollPane.setViewportView (tree);
  TreeSelectionModel tsm = tree.getSelectionModel ();
  tsm.setSelectionMode (TreeSelectionModel.SINGLE_TREE_SELECTION);

  if (adapters.size () > 0)
    restoreAdapters ();
  else
    addTreeMouseListener (new CursorHandler ());
}