This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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???
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
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Nov 05, 2001
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