2

It seems almost impossible to set the relative (Double) dividerlocation on a Scala Swing SplitPane at the time of creation of the splitpane to the desired value. The splitter nearly always appears at the top of its parent Component. I've tried using various combinations of revalidate and repaint but nothing seems to work. If I instantiate a frame with a splitpane in the constructor, make it visible and then set the split panes value, the divider appears in the correct position. It also goes to the right position if I set it by calling a function from the user interface. But I want to be able to introduce a Splipanes into already existing Frames.

Is this a known problem? Is there a solution? Should I use a timer to set the divider location after say quarter or half a second? - very messy but should work.

Some sample code, that still doesn't achieve the desired result:

val newSplit = new CSplit(Right(canv1), Right(newMapCanv))        
panel.layout(newSplit.pane) = BorderPanel.Position.Center
thisScn.visible = true
newSplit.pane.dividerLocation = 0.5 
newSplit.pane.bottomComponent = canv1
newSplit.pane.topComponent = canv2
newSplit.pane.dividerLocation = 0.5
newSplit.pane.revalidate
newSplit.pane.repaint
panel.revalidate
panel.repaint
newSplit.pane.dividerLocation = 0.5
newSplit.pane.revalidate
newSplit.pane.repaint
newSplit.pane.dividerLocation = 0.5
Rich Oliver
  • 6,001
  • 4
  • 34
  • 57

1 Answers1

2

Try setting the preferredSize of each component to 0 -> 0. Here is some code I've used while dealing with SplitPane

oneTouchExpandable = true
resizeWeight = 0.5
leftComponent.preferredSize = 0 -> 0
rightComponent.preferredSize = 0 -> 0
gerferra
  • 1,519
  • 1
  • 14
  • 26
  • Thanks, That seems to work. From what I can make out the OneTouchExpanable is not needed. – Rich Oliver Aug 23 '12 at 16:47
  • Yes, you are right. I put it there because it's part of the things I always set when I'm working with SplitPane, but it's definitely not needed. – gerferra Aug 25 '12 at 23:02