Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resizing in JSplitPane

 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am using a JSplitPane (HORIZONTAL split) to hold a JTree on the left and a JPanel containing a JList and JTable side by side on the right.
When I try to resize the JSplitPane using the divider, I cannot pull it to the left, only to the right. That is, I cannot reduce the size of the panel on the RIGHT side of the JSplitPane!
Can anyone tell me why this happens? I am fairly sure that I have not set any max/min or preferred sizes for any of the components on the RIGHT so why can't I make them smaller using the JSplitPane divider???

Please help,
Thanks in advance,
Alex
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem you are having is due to the natural behavior of JSplitPane. From the JAVA 2 API docs:
When the user is resizing the Components the minimum size of the Components is used to determine the maximum/minimum position the Components can be set to. If the minimum size of the two components is greater than the size of the split pane the divider will not allow you to resize it. To alter the minimum size of a JComponent, see JComponent.setMinimumSize(java.awt.Dimension).
When the user resizes the split pane the new space is distributed between the two components based on the resizeWeight property. A value of 0, the default, indicates the right/bottom component gets all the space, where as a value of 1 indicates the left/top component gets all the space.
You could use a PropertyChangeListener and BasicSplitPaneDivider to code in the behavior you want.
Hope this is helpful
 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a million, I used setMinimumSize to set the min size of the panel on the right, and PropertyChangeListener to detect when the divider was moved...it worked a dream
thanks
Alex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic