The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

jsplipane and resizing

Hello, newbie here.
I want to do a three way split with jsplipane (two panels on top and one at bottom).
And I want the top-left panel to remain a square no matter what. When the user moves either the vertical or horizontal splitpane (or window is resized in other ways), the three panels are to be adjusted so that the top-left pane remains a square but with different dimension. How do I achieve that ?

Re: jsplipane and resizing

Just a word to the wise, bumping your thread like that actually decreases your chances of getting help- people will see that the post has been replied to already, so they'll move on to one with zero replies instead.

But you can nest JSplitPanes, and put a PropertyChangeListener on each JSplitPane that sets the value of the other JSplitPane divider as appropriate.

Re: jsplipane and resizing

Originally Posted by KevinWorkman

Just a word to the wise, bumping your thread like that actually decreases your chances of getting help- people will see that the post has been replied to already, so they'll move on to one with zero replies instead.

Sorry but I disagree. People may equally have thought I found a solution somewhere else which I didn't. I waited for two days (48 hours as advised when I registered in the forum) before bumping... I would say that is fair, no ?

But you can nest JSplitPanes, and put a PropertyChangeListener on each JSplitPane that sets the value of the other JSplitPane divider as appropriate.

Thanks for the tip. I read the whole of the first link and a lot of other pages before I posted my question here but none addressed the problem I was having.
Also I needed to do the same thing when the window is re-sized, so I was hoping there would a "panel needs resizing" event that I can use to calculate and override the width and height.

Re: jsplipane and resizing

I tried your idea but it doesn't work. When any of them gets moved I set the others splitpane position to 0.5 but it doesn't work as intended (sometimes it does).
When the window is resized by dragging the frame, this listener doesn't sense it at all.
So my question still remains unanswered if someone wants to help..

Re: jsplipane and resizing

Originally Posted by dabdi

Sorry but I disagree. People may equally have thought I found a solution somewhere else which I didn't. I waited for two days (48 hours as advised when I registered in the forum) before bumping... I would say that is fair, no ?

It's fair, in that I'm not going to waste time arguing about the best way to receive answers- I can just tell you, from experience, what many people do is go to the "What's New?" tab, then look for posts that have zero responses. Or they use the "Unanswered Threads" link, which only shows threads with zero replies. We often don't have time to read every post. Plus, the original post seems to have been over the weekend, and I'm not sure how many people are around before Monday. Anyway, I offer that not as an argument, just something to think about for next time.

Originally Posted by dabdi

Also I needed to do the same thing when the window is re-sized, so I was hoping there would a "panel needs resizing" event that I can use to calculate and override the width and height.

Did you google anything like "panel resize listener"? I believe what you're looking for is a ComponentListener.

Re: jsplipane and resizing

Originally Posted by dabdi

I tried your idea but it doesn't work. When any of them gets moved I set the others splitpane position to 0.5 but it doesn't work as intended (sometimes it does).

That's not exactly what I said to do- I wouldn't expect setting both to .5 to accomplish your goal. You're going to have to figure out what the dimensions of the square for the upper-left component should be, which is going to be different depending on which JSplitPane was resized.

Originally Posted by dabdi

When the window is resized by dragging the frame, this listener doesn't sense it at all.

Again, I wouldn't expect it to. That's a different listener, which I mentioned above.

Another thing you might want to take into account is whether setting the divider location inside the PropertyChangeListener triggers the listener, which sets the divider location, which triggers the listener... which might lead to weird behavior.

Re: jsplipane and resizing

That's not exactly what I said to do- I wouldn't expect setting both to .5 to accomplish your goal. You're going to have to figure out what the dimensions of the square for the upper-left component should be, which is going to be different depending on which JSplitPane was resized.

Ofcourse, that was just a quick example. My actual goal is to avoid distortion of an image in a panel. So once I know the dimensions of the image, I would enforce the location of the splitpanes in such a way that the image is not distorted in any way (only scaled up or down).

Again, I wouldn't expect it to. That's a different listener, which I mentioned above.

Another thing you might want to take into account is whether setting the divider location inside the PropertyChangeListener triggers the listener, which sets the divider location, which triggers the listener... which might lead to weird behavior.

Exactly. This method sounds recursive and has already given me weird behaviours. So instead of listening for splitpane movements, I would prefer listening to resizing event for the panel which contains the image (if there is one). Only one listener will be needed in that case. But even with that I am afraid there could be the same problem... Maybe if there is an event which tells "component is about to be resized" ?

Re: jsplipane and resizing

Finally it works, with a bit of a hack though When panel is resized , set the divider location (avoids recursion) instead of resizing immediately. And also set the divider_resize_weight to some random value so that the component listener is triggered when window frame is resized. Without the latter panel doesn't adjust itself.
Thanks