Link to home
Start Free TrialLog in
Avatar of zzynx
zzynxFlag for Belgium

asked on

What's the use of JSplitPane's setLastDividerLocation?

Hi experts,

Can anybody explain me what I could use JSplitPane's method setLastDividerLocation() for?
Any (URL containing) example code?

Thanks
Avatar of Mick Barry
Mick Barry
Flag of Australia image

so u can reset it to the previous location it was set at.

split.setDividerLocation(split.getLastDividerLocation());
Avatar of zzynx

ASKER

So the java guys have just foreseen the field 'lastDividerLocation' (+ setter/getter) to store a location in case you want to use it later on?
Why? I can do that in just simple variable, can't I?
Avatar of sciuriware
sciuriware

It's an "UNDO".

;JOOP!
Avatar of zzynx

ASKER

>> It's an "UNDO".
Would you mind to explain that in more detail?
After manual operations with the mouse you can quickly reset to the previous state.
Most of those manual operations are temporary or not very exact.

;JOOP!
Avatar of zzynx

ASKER

>> here is the example
>> http://kickjava.com/src/javax/swing/plaf/basic/BasicSplitPaneDivider.java.htm
>> http://kickjava.com/tops/t351.htm
I was not looking for just JSplitPane examples.
I'm looking for an example that explains what JSplitPane's setLastDividerLocation() is used for.
Avatar of zzynx

ASKER

>> After manual operations with the mouse you can quickly reset to the previous state.
By using what object posted, I suppose:
   >> split.setDividerLocation(split.getLastDividerLocation());

But I'm not asking why you use getLastDividerLocation() for. I'm talking about the setter.
Sigh... Apparently we don't understand each other.
>>http://kickjava.com/src/javax/swing/plaf/basic/BasicSplitPaneDivider.java.htm
the above example uses getLastDividerLocation()
you will know how the method can be used and for what purpose
Avatar of zzynx

ASKER

Moreover
>> Most of those manual operations are temporary
Are they? If a user drags the divider, what's temporary on that?
Avatar of zzynx

ASKER

>> you will know how the method can be used and for what purpose
When I read that example I have the impression that the field 'lastDividerLocation'
is just used if isOneTouchExpandable() is true.

Am I right?
Some detailed explanation someone?
Avatar of zzynx

ASKER

I hope some of you are thinking about what to answer me...
Or do you guys just roll your eyes about my ignorance?
Avatar of zzynx

ASKER

OK. I found this quote in an old version of "JFC Unleashed" by Michael Foley:

The previous divider location is a bound property of the split pane. When the continuous layout property is false, a
property change listener will be notified of the last divider location after a drag operation is complete. The name of the
property in the PropertyChangeEvent is the String defined by the LAST_DIVIDER_LOCATION_PROPERTY
constant in the JSplitPane class. If the continuous layout property is true, the listener will receive a stream of
change events as the user drags the divider. The getDividerLocation method can be used to query the current
location of the divider in the propertyChange method. The getLastDividerLocation method can be called to
query the divider's previous location. This value is also delivered to listeners by the PropertyChange event.

There is a setLastDividerLocation method that is used by the look-and-feel implementations to set this property
and initiate the PropertyChangeEvent being fired. ***This method is rarely used by user applications.***

That was the kind of information I was looking for.

No points to distrubute.
CV, you can close or PAQ this Q.
Honestly - I never used this one. Saw it but decided it is there just to be a pair with the get method :))
>  I'm talking about the setter. Sigh... Apparently we don't understand each other.

the setter is needed to set it. you don't need to call it, it is looked after for you.



Avatar of zzynx

ASKER

;°)
Thanks for that info
Avatar of zzynx

ASKER

My previous post was for Venabili.

>> you don't need to call it, it is looked after for you.
That's what the quote I found seems to indicate. Yes.
Just decided to post because you seemed a bit unhappy :) And I posted before I saw your long post... sigh - I need to refresh sometimes.

Interesting information from you -- sounds reasonable. Although with all the get/set methods, I never think again why there is a set that is useless for me -- :)
its a property, so it has a getter and a setter which you use like any other getter/setter. The important thing to understand is how the property is usewd (we all know how to call getters/setters)

>  I never think again why there is a set that is useless for me -- :)

Its not useless to you, as there may be a app requement that requires u to set it.
Also it needs to be there so the listener can set it.
Avatar of zzynx

ASKER

>> Just decided to post because you seemed a bit unhappy :)
Thanks for your support in that.
>> sigh - I need to refresh sometimes.
Glad to see I'm not the only one ;°)

>> The important thing to understand is how the property is usewd
That was exactly the information I was looking for
If I need to set it, I know that it exists and I will figure it out then. But when I was using swing, I never needed it.
As I said - if there is a get method, the setter should be somewhere there also.
> That was exactly the information I was looking for

which is exactly what I posted :)
Its a memento or token design-pattern implementation ;-) he he.
Looking at BasicSplitPaneUI source code you'll find the only usage of setLastDividerLocation

                  // This is not always needed, but is rather tricky
                  // to determine when... The case this is needed for
                  // is if the user sets the divider location to some
                  // bogus value, say 0, and the actual value is 1, the
                  // call to setDividerLocation(1) will preserve the
                  // old value of 0, when we really want the divider
                  // location value  before the call. This is needed for
                  // the one touch buttons.
                  splitPane.setLastDividerLocation(lastLocation);
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial