JTree: getMinSelectionRow() : JTree « javax.swing « Java by API






JTree: getMinSelectionRow()

  

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

public class Main {
  public static void main(String args[]) {
    String title = "JTree Sample";
    JFrame frame = new JFrame(title);
    JTree tree = new JTree();
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
        JTree treeSource = (JTree) treeSelectionEvent.getSource();
        System.out.println("Min: " + treeSource.getMinSelectionRow());
        System.out.println("Max: " + treeSource.getMaxSelectionRow());
        System.out.println("Lead: " + treeSource.getLeadSelectionRow());
        System.out.println("Row: " + treeSource.getSelectionRows()[0]);
      }
    };
    tree.addTreeSelectionListener(treeSelectionListener);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.Tree.closedIcon
2.Tree.collapsedIcon
3.Tree.expandedIcon
4.Tree.leafIcon
5.Tree.openIcon
6.JTree.DynamicUtilTreeNode: createChildren(DefaultMutableTreeNode parent, Object children)
7.new JTree()
8.new JTree(TreeNode root)
9.new JTree(Vector vector)
10.JTree: addTreeSelectionListener(TreeSelectionListener tsl)
11.JTree: addTreeWillExpandListener(TreeWillExpandListener tel)
12.JTree: convertValueToText(Object v,boolean s,boolean e,boolean l,int r,boolean h)
13.JTree: getCellRenderer()
14.JTree: getLeadSelectionRow()
15.JTree: getMaxSelectionRow()
16.JTree: getNextMatch(String prefix, int startingRow, Bias bias)
17.JTree: getPathForLocation(int x, int y)
18.JTree: getRowHeight()
19.JTree: getSelectionRows()
20.JTree: putClientProperty('JTree.lineStyle', 'None')
21.JTree: setAutoscrolls(boolean b)
22.JTree: setCellEditor(TreeCellEditor editor)
23.JTree: setExpandedState(TreePath path, boolean state)
24.JTree: setRowHeight(int rowHeight)
25.JTree: setTransferHandler(TransferHandler newHandler) (Drag and drop files from file explore)