Java JTree set visible row count

Description

Java JTree set visible row count

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

public class Main {

  public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    root.add(new DefaultMutableTreeNode("A"));
    root.add(new DefaultMutableTreeNode("B"));
    root.add(new DefaultMutableTreeNode("C"));
    JTree tree = new JTree(root);

    tree.setVisibleRowCount(12);/*from  ww w  .  ja va2 s .c  om*/

    frame.add(new JScrollPane(tree));

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

}



PreviousNext

Related