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
LVL 37
zzynxSr. Software engineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
so u can reset it to the previous location it was set at.

split.setDividerLocation(split.getLastDividerLocation());
zzynxSr. Software engineerAuthor Commented:
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?
sciuriwareCommented:
It's an "UNDO".

;JOOP!
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

zzynxSr. Software engineerAuthor Commented:
>> It's an "UNDO".
Would you mind to explain that in more detail?
sciuriwareCommented:
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!
zzynxSr. Software engineerAuthor Commented:
>> 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.
zzynxSr. Software engineerAuthor Commented:
>> 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.
mbvvsatishCommented:
>>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
zzynxSr. Software engineerAuthor Commented:
Moreover
>> Most of those manual operations are temporary
Are they? If a user drags the divider, what's temporary on that?
zzynxSr. Software engineerAuthor Commented:
>> 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?
zzynxSr. Software engineerAuthor Commented:
I hope some of you are thinking about what to answer me...
Or do you guys just roll your eyes about my ignorance?
zzynxSr. Software engineerAuthor Commented:
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.
VenabiliCommented:
Honestly - I never used this one. Saw it but decided it is there just to be a pair with the get method :))
Mick BarryJava DeveloperCommented:
>  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.



zzynxSr. Software engineerAuthor Commented:
;°)
Thanks for that info
zzynxSr. Software engineerAuthor Commented:
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.
VenabiliCommented:
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 -- :)
Mick BarryJava DeveloperCommented:
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.
zzynxSr. Software engineerAuthor Commented:
>> 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
VenabiliCommented:
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.
Mick BarryJava DeveloperCommented:
> That was exactly the information I was looking for

which is exactly what I posted :)
Mayank SPrincipal TechnologistCommented:
Its a memento or token design-pattern implementation ;-) he he.
hoomanvCommented:
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);
Computer101Commented:
PAQed with points refunded (250)

Computer101
EE Admin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.