File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Resizing in JSplitPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Resizing in JSplitPane" Watch "Resizing in JSplitPane" New topic
Author

Resizing in JSplitPane

alex earnshaw
Ranch Hand

Joined: Nov 05, 2001
Posts: 60
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

Joined: Jan 30, 2002
Posts: 3451
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
alex earnshaw
Ranch Hand

Joined: Nov 05, 2001
Posts: 60
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
 
jQuery in Action, 2nd edition
 
subject: Resizing in JSplitPane
 
Similar Threads
how to keep JSplitPane from resizing
Weird JSplitPane behaviour on frame resize (bug?)
Problem with split panes
Problem in JDialogBox
JSplitPane and its setDividerLocation method