Example usage for javax.swing JTree setVisibleRowCount

List of usage examples for javax.swing JTree setVisibleRowCount

Introduction

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

Prototype

@BeanProperty(description = "The number of rows that are to be displayed.")
public void setVisibleRowCount(int newCount) 

Source Link

Document

Sets the number of rows that are to be displayed.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTree tree = new JTree();
    tree.setVisibleRowCount(10);
    JOptionPane.showMessageDialog(null, new JScrollPane(tree));
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    final ConfirmDialog dialog = new ConfirmDialog(f);
    final JTree tree = new JTree();
    tree.setVisibleRowCount(5);
    final JScrollPane treeScroll = new JScrollPane(tree);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton b = new JButton("Choose Tree Item");
    b.addActionListener(e -> {//from w  w w  .  ja va2  s  .  c  om
        int result = dialog.showConfirmDialog(treeScroll, "Choose an item");
        if (result == ConfirmDialog.OK_OPTION) {
            System.out.println(tree.getSelectionPath());
        } else {
            System.out.println("User cancelled");
        }
    });
    JPanel p = new JPanel(new BorderLayout());
    p.add(b);
    p.setBorder(new EmptyBorder(50, 50, 50, 50));
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    final JTree tree = new JTree(buildDemoModel());

    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        private Icon loadIcon = UIManager.getIcon("OptionPane.errorIcon");
        private Icon saveIcon = UIManager.getIcon("OptionPane.informationIcon");

        @Override/*w  w  w.  j  a  v  a2s  . c  o m*/
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row,
                    focused);
            if (selected)
                setIcon(loadIcon);
            else
                setIcon(saveIcon);
            return c;
        }
    });
    tree.setVisibleRowCount(10);
    frame.add(new JScrollPane(tree));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}