Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSplitPanes not resizing when JFrame maximized

 
Brady Diggs
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all -
I've got a JFrame with a split pane on it.
Basically all I want it to do is recall its enlarged size when the frame is enlarged.
First I open the frame. Then I shrink the split pane to 15% of the frame size. Then I enlarge
the frame and drag the split pane divider to enlarge it (75% of the frame size). So far so good.
Then I double-click on the window's title bar to shrink the frame. The split pane shrinks down
to its original (15%) size. Super. Great. Everything is fine so far.
But....
when I enlarge the frame via the maximize window button or a double-click on the title bar,
the split pane does not size back to it's enlarged (75%) state.
I can maximize it and minimize it all day long and it always remembers its original (15%) size,
but not its enlarged size.
Question: How/why can it remember it's small size, but not it's bigger size?

I saw this:

http://forums.sun.com/thread.jspa?threadID=680276

but neither of those solutions worked for me. I played with the resize weight, but to no avail.

Does anyone have any insight into this?
Thanks so much in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's always best to post a working demo, so there's no confusion:

'First I open the frame. Then I shrink the split pane to 15% of the frame size.'
all of the splitpane is 15% of the frame size?

'Then I enlarge the frame and drag the split pane divider to enlarge it (75% of the frame size)'
is the splitpane now all of the frame size, and the earlier bit should be 15% for the divider?

a possible solution would be to add a componentListener to the frame (not the contentPane),
and in componentResized check the size/state of the frame then set the dividerLocation
 
Brady Diggs
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for responding.
I've taken your advice and posted some code that shows the problem (I hope adequately).

Here are the steps to reproduce what I'm doing:
1) Run the code below and maximize the frame (either with the window icon or double-click the title bar).
2) Drag the left divider as far as you can to the right, making the left pane very large.
3) Restore the frame down to the original size.
4) Note that the resized left pane maintains some sense of porportion, but because the frame is smaller, it does shrink.
5) Now here's the fun part: maximize the frame again. Observe that the left divider
that you moved over to the right in step 2 does not go back to its enlarged state, but
stays where it was positioned when you restored the frame down in step 3.

You can also see the same behavior with Sun's demo here:
http://java.sun.com/docs/books/tutorial/uiswing/components/splitpane.html
Just launch the demo and follow my steps above.
And here's the source for that:
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/SplitPaneDemoProject/src/components/SplitPaneDemo.java

The big question here is this:
Why does the container/frame remember the original size/position, but not the maxed size/position?
And how can I get it to remember this position? I've tried changing the resize weight, but that doesn't seem to
affect anything.

Thanks very much in advance for your time! I appreciate the help.


 
Fire me boy! Cool, soothing, shameless self promotion:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!