aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Weird JSplitPane behaviour on frame resize (bug?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Weird JSplitPane behaviour on frame resize (bug?)" Watch "Weird JSplitPane behaviour on frame resize (bug?)" New topic
Author

Weird JSplitPane behaviour on frame resize (bug?)

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

I'm trying to make a GUI that includes several split panes, and am finding that the movement of the divider seems to depend on how fast you resize the window.

In a configuration with a left-right JSplitPane with a panel weighting of 0.5, i.e the divider is supposed to stay in the middle: if you grab the right or left side of the frame and drag it slowly, only that half of the splitpane changes size. If you drag it faster, the divider moves (although not as much as it should to keep the divider centred).

I'm running on Windows 7 x64 - does anyone else get this problem?

You can try it with Sun's own demo here (java web start)
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

As a guess, what might be happening is that if you only move 1 pixel before a repaint, it can't resize both sides by half a pixel, so it just resizes one half. Then you move another pixel and it resizes the same half again.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
I get the same behaviour on JDK6 on XP. I would say your guess as to the cause is reasonable. I don't see any solution since the code can't just divide the space evenly because the user may manually have moved the divide.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Happens with the splits in the NetBeans IDE GUI as well. If you have the Projects window above the Navigator window and resize the screen vertically a bit, then back to the original size, the location of the split will be different.

If the bug is due to my guess, the solution would be easy: either have a variable that remembers which half the half pixel was awarded to last time, or (equivalently) store the divider position as a float. If a user changes the position, it will only be by whole pixels.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird JSplitPane behaviour on frame resize (bug?)