Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems Sizing a JTree

Henrietta Martin
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to display a JTree within a ScrollPane. Works fine. However....
I'm trying to specify how much space I want the JTree to take up when the tree is initially displayed, whether or not the nodes are expanded (500 X 500 for example).
2 approaches fail for different reasons:
1. setPreferredSize() works initally (I get a Tree of 500 X 500), but then if there are a lot of hidden Nodes, when I expand , it never goes over this size, so it doesn't show the Nodes. They are not even able to be Scrolled into view- the ScrollPane never seems to acknowledge that I am trying to expand the view.
2. Not setting any size works in the sense that as I expand the Nodes, it adjusts the Tree size, and the ScrollPane viewport opens up to allow scrolling to the newly visible Nodes. BUT! in this case the initial size of the tree is set to whatever is the minimum possible to initally display the data (unexpanded). This is like 200 X 200. It eventually will go beyond 500 by 500 but until then it looks too small.
I tried setting Minumum Size but that seemed to be ignored. I am using a GridBagLayout. Is this part of the problem? But if GridBagLayout is ignoring my request for a MinimumSize, why wouldn't it also ignore my request for a Preferred Size?
Any advice?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic