Quantcast

2.0.2 How to move scroll bar to bottom of ScrollPane?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

2.0.2 How to move scroll bar to bottom of ScrollPane?

Jason Murray
Right now, I have a TextArea set to refresh its text after the enter
key is pressed.
This works just fine, but the scroll bar of the ScrollPane that the
TextArea is in doesn't automatically scroll down to the bottom where
anything new would be.
Is there a method of ScrollPane that I could put inside an event
listener to do this?
--Jason
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: 2.0.2 How to move scroll bar to bottom of ScrollPane?

Roger Whitcomb-2
Hi Jason,
        The way we handle this case is to queue a callback that gets the Bounds of the last character and calls "scrollAreaToVisible" with those bounds.  Like this:
            ApplicationContext.queueCallback(new Runnable() {
                @Override
                public void run() {
                    Bounds bounds = resultArea.getCharacterBounds(resultArea.getCharacterCount());
                    resultArea.scrollAreaToVisible(bounds);
                }
            });

The reason you have to do the queued callback is that the painting code is what actually sets the bounds, and so the value is not available until the repaint happens, and then the callback is invoked right after that.

HTH,
~Roger Whitcomb

-----Original Message-----
From: Jason Murray [mailto:[hidden email]]
Sent: Saturday, December 01, 2012 8:29 PM
To: [hidden email]
Subject: 2.0.2 How to move scroll bar to bottom of ScrollPane?

Right now, I have a TextArea set to refresh its text after the enter key is pressed.
This works just fine, but the scroll bar of the ScrollPane that the TextArea is in doesn't automatically scroll down to the bottom where anything new would be.
Is there a method of ScrollPane that I could put inside an event listener to do this?
--Jason
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 2.0.2 How to move scroll bar to bottom of ScrollPane?

Jason Murray
Thank you very much, that works perfectly! So anything that is set
after it's painted requires a callback?
--Jason


On Tue, Dec 4, 2012 at 10:52 AM, Roger L. Whitcomb
<[hidden email]> wrote:

> Hi Jason,
>         The way we handle this case is to queue a callback that gets the
> Bounds of the last character and calls "scrollAreaToVisible" with those
> bounds.  Like this:
>             ApplicationContext.queueCallback(new Runnable() {
>                 @Override
>                 public void run() {
>                     Bounds bounds =
> resultArea.getCharacterBounds(resultArea.getCharacterCount());
>                     resultArea.scrollAreaToVisible(bounds);
>                 }
>             });
>
> The reason you have to do the queued callback is that the painting code is
> what actually sets the bounds, and so the value is not available until the
> repaint happens, and then the callback is invoked right after that.
>
> HTH,
> ~Roger Whitcomb
>
> -----Original Message-----
> From: Jason Murray [mailto:[hidden email]]
> Sent: Saturday, December 01, 2012 8:29 PM
> To: [hidden email]
> Subject: 2.0.2 How to move scroll bar to bottom of ScrollPane?
>
> Right now, I have a TextArea set to refresh its text after the enter key
> is pressed.
> This works just fine, but the scroll bar of the ScrollPane that the
> TextArea is in doesn't automatically scroll down to the bottom where
> anything new would be.
> Is there a method of ScrollPane that I could put inside an event listener
> to do this?
> --Jason
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 2.0.2 How to move scroll bar to bottom of ScrollPane?

Roger and Beth Whitcomb
Hi Jason,
     It's not exactly that.  It's just that in the case of TextArea all
the real calculations happen as part of the painting code, so the bounds
of the last character don't calculate right unless we let the paint
happen before trying to get the bounds.  Not all components are like
that.  And I suppose, ideally, TextArea wouldn't be like that either,
but ....

HTH,
~Roger

On 12/6/12 9:49 PM, Jason Murray wrote:

> Thank you very much, that works perfectly! So anything that is set
> after it's painted requires a callback?
> --Jason
>
>
> On Tue, Dec 4, 2012 at 10:52 AM, Roger L. Whitcomb
> <[hidden email]> wrote:
>> Hi Jason,
>>          The way we handle this case is to queue a callback that gets the
>> Bounds of the last character and calls "scrollAreaToVisible" with those
>> bounds.  Like this:
>>              ApplicationContext.queueCallback(new Runnable() {
>>                  @Override
>>                  public void run() {
>>                      Bounds bounds =
>> resultArea.getCharacterBounds(resultArea.getCharacterCount());
>>                      resultArea.scrollAreaToVisible(bounds);
>>                  }
>>              });
>>
>> The reason you have to do the queued callback is that the painting code is
>> what actually sets the bounds, and so the value is not available until the
>> repaint happens, and then the callback is invoked right after that.
>>
>> HTH,
>> ~Roger Whitcomb
>>
>> -----Original Message-----
>> From: Jason Murray [mailto:[hidden email]]
>> Sent: Saturday, December 01, 2012 8:29 PM
>> To: [hidden email]
>> Subject: 2.0.2 How to move scroll bar to bottom of ScrollPane?
>>
>> Right now, I have a TextArea set to refresh its text after the enter key
>> is pressed.
>> This works just fine, but the scroll bar of the ScrollPane that the
>> TextArea is in doesn't automatically scroll down to the bottom where
>> anything new would be.
>> Is there a method of ScrollPane that I could put inside an event listener
>> to do this?
>> --Jason
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 2.0.2 How to move scroll bar to bottom of ScrollPane?

Jason Murray
Alright thanks, Roger. I now realize it would probably do me buckets
of good to look through the source instead of just the javadocs and
tutorials..
Thanks again for your help
--Jason


On Thu, Dec 6, 2012 at 11:27 PM, Roger and Beth Whitcomb
<[hidden email]> wrote:

> Hi Jason,
>     It's not exactly that.  It's just that in the case of TextArea all the
> real calculations happen as part of the painting code, so the bounds of the
> last character don't calculate right unless we let the paint happen before
> trying to get the bounds.  Not all components are like that.  And I suppose,
> ideally, TextArea wouldn't be like that either, but ....
>
> HTH,
> ~Roger
>
>
> On 12/6/12 9:49 PM, Jason Murray wrote:
>>
>> Thank you very much, that works perfectly! So anything that is set
>> after it's painted requires a callback?
>> --Jason
>>
>>
>> On Tue, Dec 4, 2012 at 10:52 AM, Roger L. Whitcomb
>> <[hidden email]> wrote:
>>>
>>> Hi Jason,
>>>          The way we handle this case is to queue a callback that gets the
>>> Bounds of the last character and calls "scrollAreaToVisible" with those
>>> bounds.  Like this:
>>>              ApplicationContext.queueCallback(new Runnable() {
>>>                  @Override
>>>                  public void run() {
>>>                      Bounds bounds =
>>> resultArea.getCharacterBounds(resultArea.getCharacterCount());
>>>                      resultArea.scrollAreaToVisible(bounds);
>>>                  }
>>>              });
>>>
>>> The reason you have to do the queued callback is that the painting code
>>> is
>>> what actually sets the bounds, and so the value is not available until
>>> the
>>> repaint happens, and then the callback is invoked right after that.
>>>
>>> HTH,
>>> ~Roger Whitcomb
>>>
>>> -----Original Message-----
>>> From: Jason Murray [mailto:[hidden email]]
>>> Sent: Saturday, December 01, 2012 8:29 PM
>>> To: [hidden email]
>>> Subject: 2.0.2 How to move scroll bar to bottom of ScrollPane?
>>>
>>> Right now, I have a TextArea set to refresh its text after the enter key
>>> is pressed.
>>> This works just fine, but the scroll bar of the ScrollPane that the
>>> TextArea is in doesn't automatically scroll down to the bottom where
>>> anything new would be.
>>> Is there a method of ScrollPane that I could put inside an event listener
>>> to do this?
>>> --Jason
>>
>>
>
Loading...