Skip to main content

Programmatically move divider/separator in JXMultiSplitPane

6 replies [Last post]
amtree
Offline
Joined: 2009-04-20
Points: 0

Hi all,

I've recently discovered JXMultiSplitPane and it's fantastic to use. However I could not find an equivalent setDividerLocation() method that was present in JSplitPane. Could anyone tell me how I could programmatically move the divider in JXMultiSplitPane?

My reasons for wanting this are as follows:

Say I have 2 components (A and B for simplicity's sake) divided in the middle. I would like to dynamically add components in A, however, when the scrollbar appears, I would like to move the divider to accommodate for the scrollbar by taking some of B's space. When I was using JSplitPane, I did this programmatically by moving the divider. I cannot use JSplitPane because I have more than 2 dividers and I do not want to nest multiple JSplitPanes.

Any help or hints towards the right direction would be much appreciated. Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jozza
Offline
Joined: 2009-04-14
Points: 0

I will give that a try

luano
Offline
Joined: 2003-06-12
Points: 0

You can get a node from the layout and set its weight, to give you some control, but achieving what you describe is going to be difficult.

Also once the user starts moving the dividers the scrollbar may again consume some space from one of your components.

jozza
Offline
Joined: 2009-04-14
Points: 0

It's a shame it doesn't allow you access to the dividerLocation to either get/set it. I used JXMultiSplitPane to replace my own Implemention of nested JSplitPane which I was having difficulty with but was surprised to realise you cant programmticaly set the dividerLocation on JXMultiSplitPane . Very dissapointed as i invested considerable time getting JXMultiSplitPane to work. :-(

luano
Offline
Joined: 2003-06-12
Points: 0

Did you try setting the node weights as suggested? What was your experience?

jozza
Offline
Joined: 2009-04-14
Points: 0

I will give that a try

sbozian
Offline
Joined: 2010-08-30
Points: 0

Hi all,

I'm currently facing the problem of programmatically moving the divider in JXMultiSplitPane too!

Were you eventually able to solve this problem?

I tried to "get a node from the layout and set its weight" as suggested here, but here's the issue I faced: setting the weight of a node is being actually able to relocate the corresponding divider as desired, but this is only working if none of the dividers are touched (i.e. moved) by the user yet; i.e. if I want to take the action of setting the weight dynamically, for example, when clicking some button, the divider moves on the button click only if it is not touched by the user yet. In other words, if I run my test, and click the button, I see a change. Whereas if I run my test, move the divider manually, then click the button, nothing happens.

I'm not very familiar with JXMultiSplitPane yet, but this behavior means that those weights are used only for the initial rendering of the panels, but once the panels are resized, resetting a weight doesn't have any effect. Am I right? If yes, what is the correct way to move the divider programmatically at runtime then?

Thank you,
Shant