0

I know how to add a tree inside JScrollpane. Some thing like this

JScrollPane treePane = new JScrollPane(tree);
treePane.setBorder(null);
tree.setPreferredSize(null);
treePane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
holder.add(treePane);// holder is a JPanel

This makes the entire tree scrollable. I want only the node items to be scrollable. I have a cutsom cell renderer written . That returns a specific JPanel for each leaf node.

So i want to know is it possible to display only the nodes inside a JScrollPane?? Here is the screenshot of my current tree.

enter image description here

ayush
  • 14,350
  • 11
  • 53
  • 100
  • 1
    `tree.setPreferredSize(null);` isn't about good practicies, not to `setPreferredSize` – mKorbel Jan 07 '14 at 15:00
  • i want to know is it possible to display only the nodes inside a JScrollPane?? --> DYm to remove leaf and root – mKorbel Jan 07 '14 at 15:01
  • i want to know is it possible to display only the nodes inside a JScrollPane?? --> use JTable instead of JTree – mKorbel Jan 07 '14 at 15:08
  • @mKorbel : is it not possible to display nodes inside JScollPane using JTree??I want the root to be shown as it is just that the leaf nodes come inside a JScollPane ( all of them). – ayush Jan 07 '14 at 16:31
  • @mKorbel: Can you please point me towards a link where the same has been acheived in a JTable. I really wanted to know if it is possible to acheive what i am trying inside a JTree!! As you can see in the screenshot that when i will scroll down a tree even the root node( which is a jlabel) will scroll down.. I don't want that to happen.. – ayush Jan 07 '14 at 17:35
  • 1
    [accordion](https://www.google.sk/search?q=accordion+in+java&ie=utf-8&oe=utf-8&rls=org.mozilla:cs:official&client=firefox-a&gws_rd=cr&ei=JFjMUrzdGannywOHmoL4Aw#q=accordion+in+java+swing&rls=org.mozilla:cs:official) ???, [then the same suggestion for your another question about](http://stackoverflow.com/a/10299581/714968) or JTreeTable by Jide (non_free) or SwingX (free) – mKorbel Jan 07 '14 at 19:42
  • `tree.setPreferredSize(null);` Don't do that. That alone could cause the problem. Instead look to methods like [`setVisibleRowCount(int)`](http://docs.oracle.com/javase/7/docs/api/javax/swing/JTree.html#setVisibleRowCount%28int%29).. – Andrew Thompson Jan 08 '14 at 00:44
  • For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Jan 08 '14 at 00:45
  • @mKorbel : I was using SwingX but then i got stuck with a cell editor issue in SwingX. (http://stackoverflow.com/questions/20909379/jxtreetable-custom-cell-editor). Any comments on how to move ahead for that issue? – ayush Jan 08 '14 at 11:12

0 Answers0