Skip to main content

ScrollBar management

5 replies [Last post]
Anonymous

I have introduced a bit of code under:

jdnc-incubator/src/java/org/jdesktop/jdnc/incubator/gonzo/editor

With the goal being to adjust the JXEditorPane's scrollbar iff the scrollbar
is at the end/maximum position, otherwise leave it in the current position.
The implementation strategy basically captures the viewport position just
prior to appending the new text. if the position is not at the end/maximum
then the viewport is adjusted under a EventQueue.invokeLater() thread.

The code appears to work fine in the standalone app (ie incubator) but when
included within a larger Swing application (myjxta2.jxta.org) it fails.

Any ideas?

While I'm at it, any pointers on how best to capture and consume (vs propogate)
a enter key press event? By adding a KeyListener to my JXEditorPane I can see
when the key is pressed but I'm not sure how best to prevent the kestroke from
getting processed by the underlying document.

much appreciated,

- james

--
Java == platform independence
XML == application independence
JXTA == network independence

Secure End-to-End Computing

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Scott Violet

On Thu, Sep 30, 2004 at 04:10:54AM -0700, James Todd wrote:
>
> I have introduced a bit of code under:
>
> jdnc-incubator/src/java/org/jdesktop/jdnc/incubator/gonzo/editor
>
> With the goal being to adjust the JXEditorPane's scrollbar iff the scrollbar
> is at the end/maximum position, otherwise leave it in the current position.
> The implementation strategy basically captures the viewport position just
> prior to appending the new text. if the position is not at the end/maximum
> then the viewport is adjusted under a EventQueue.invokeLater() thread.
>
> The code appears to work fine in the standalone app (ie incubator) but when
> included within a larger Swing application (myjxta2.jxta.org) it fails.
>
> Any ideas?

I suspect you are fighting with DefaultCaret. The text components, by
way of DefaultCaret, try to make sure the location of the caret is
visible and use scrollRectToVisible for that. It's possible you're
doing a scrollRectToVisible, and then the text components are also
doing a scrollRectToVisible. To verify this is what's happening I
would override scrollRectToVisible and see who is calling it.

> While I'm at it, any pointers on how best to capture and consume (vs
> propogate)
> a enter key press event? By adding a KeyListener to my JXEditorPane I can
> see
> when the key is pressed but I'm not sure how best to prevent the kestroke
> from
> getting processed by the underlying document.

You're listener is notified first, if you consume the event than
JXEditorPane won't process the key event.

-Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

James Todd

Thx Scott.

I should've added, I'm using version 1.4.2_04.

Further the JXEditorPane I'm working with is not editable. I'm not sure if
this applies or not. The single method I'm using to (optionally) adjust the
ScrollBar is:

sb.getViewport().setViewPosition(p);

where p is a Point and was evaluated just prior to adding the text.

It is really odd that the code works under the jdnc-incubator (trivial stand
alone) yet seems to always scroll to end when embedded within a larger app
although I'm using JXFrame and the panel is roughly equivalent.

That aside, I will try to work in your suggestions.

> You're listener is notified first, if you consume the event than
> JXEditorPane won't process the key event.

I assume you mean KeyListener? If so, I've implemented the following
first attempt which echos to the command line yet still inserts a
newline.

this.htmlEditor.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
System.out.println("enter");
}
}
});

I suspect I'm missing something really silly here. Late nighter, looking
at the code too long kind of thing.

That aside, I'd love to get these two issues addressed as the remaining
UI work should be relatively straight forward.

much appreciated,

- james

Java == platform independence
XML == application independence
JXTA == network independence

Secure End-to-End Computing

Scott Violet wrote:
> On Thu, Sep 30, 2004 at 04:10:54AM -0700, James Todd wrote:
>
>>I have introduced a bit of code under:
>>
>> jdnc-incubator/src/java/org/jdesktop/jdnc/incubator/gonzo/editor
>>
>>With the goal being to adjust the JXEditorPane's scrollbar iff the scrollbar
>>is at the end/maximum position, otherwise leave it in the current position.
>>The implementation strategy basically captures the viewport position just
>>prior to appending the new text. if the position is not at the end/maximum
>>then the viewport is adjusted under a EventQueue.invokeLater() thread.
>>
>>The code appears to work fine in the standalone app (ie incubator) but when
>>included within a larger Swing application (myjxta2.jxta.org) it fails.
>>
>>Any ideas?
>
>
> I suspect you are fighting with DefaultCaret. The text components, by
> way of DefaultCaret, try to make sure the location of the caret is
> visible and use scrollRectToVisible for that. It's possible you're
> doing a scrollRectToVisible, and then the text components are also
> doing a scrollRectToVisible. To verify this is what's happening I
> would override scrollRectToVisible and see who is calling it.
>
>
>>While I'm at it, any pointers on how best to capture and consume (vs
>>propogate)
>>a enter key press event? By adding a KeyListener to my JXEditorPane I can
>>see
>>when the key is pressed but I'm not sure how best to prevent the kestroke
>>from
>>getting processed by the underlying document.
>
>
> You're listener is notified first, if you consume the event than
> JXEditorPane won't process the key event.
>
> -Scott
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Scott Violet

On Thu, Sep 30, 2004 at 10:07:13AM -0700, James Todd wrote:
>
> Thx Scott.
>
> I should've added, I'm using version 1.4.2_04.
>
> Further the JXEditorPane I'm working with is not editable. I'm not sure if
> this applies or not. The single method I'm using to (optionally) adjust the
> ScrollBar is:
>
> sb.getViewport().setViewPosition(p);

Even better. That means you're not invoking scrollRectToVisible so
that if you put a breakpoint in scrollRectToVisible you'll be able to
see why it's getting called.

> where p is a Point and was evaluated just prior to adding the text.
>
> It is really odd that the code works under the jdnc-incubator (trivial stand
> alone) yet seems to always scroll to end when embedded within a larger app
> although I'm using JXFrame and the panel is roughly equivalent.

That's for sure!

> That aside, I will try to work in your suggestions.
>
> >You're listener is notified first, if you consume the event than
> >JXEditorPane won't process the key event.
>
> I assume you mean KeyListener?

Yep.

> If so, I've implemented the following
> first attempt which echos to the command line yet still inserts a
> newline.
>
> this.htmlEditor.addKeyListener(new KeyAdapter() {
> public void keyPressed(KeyEvent ke) {
> if (ke.getKeyCode() ==
> KeyEvent.VK_ENTER) {
> System.out.println("enter");
> }
> }
> });

Try adding ke.consume().

-Scott

> I suspect I'm missing something really silly here. Late nighter, looking
> at the code too long kind of thing.
>
> That aside, I'd love to get these two issues addressed as the remaining
> UI work should be relatively straight forward.
>
> much appreciated,
>
> - james
>
> Java == platform independence
> XML == application independence
> JXTA == network independence
>
> Secure End-to-End Computing
>
>
> Scott Violet wrote:
> >On Thu, Sep 30, 2004 at 04:10:54AM -0700, James Todd wrote:
> >
> >>I have introduced a bit of code under:
> >>
> >> jdnc-incubator/src/java/org/jdesktop/jdnc/incubator/gonzo/editor
> >>
> >>With the goal being to adjust the JXEditorPane's scrollbar iff the
> >>scrollbar
> >>is at the end/maximum position, otherwise leave it in the current
> >>position.
> >>The implementation strategy basically captures the viewport position just
> >>prior to appending the new text. if the position is not at the end/maximum
> >>then the viewport is adjusted under a EventQueue.invokeLater() thread.
> >>
> >>The code appears to work fine in the standalone app (ie incubator) but
> >>when
> >>included within a larger Swing application (myjxta2.jxta.org) it fails.
> >>
> >>Any ideas?
> >
> >
> >I suspect you are fighting with DefaultCaret. The text components, by
> >way of DefaultCaret, try to make sure the location of the caret is
> >visible and use scrollRectToVisible for that. It's possible you're
> >doing a scrollRectToVisible, and then the text components are also
> >doing a scrollRectToVisible. To verify this is what's happening I
> >would override scrollRectToVisible and see who is calling it.
> >
> >
> >>While I'm at it, any pointers on how best to capture and consume (vs
> >>propogate)
> >>a enter key press event? By adding a KeyListener to my JXEditorPane I can
> >>see
> >>when the key is pressed but I'm not sure how best to prevent the kestroke
> >>from
> >>getting processed by the underlying document.
> >
> >
> >You're listener is notified first, if you consume the event than
> >JXEditorPane won't process the key event.
> >
> > -Scott
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> >For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

James Todd

> Even better. That means you're not invoking scrollRectToVisible so
> that if you put a breakpoint in scrollRectToVisible you'll be able to
> see why it's getting called.

will do.

>>I assume you mean KeyListener?

ahhh, much appreciated. i hit a mental block.

that scroller issue is consuming my mind as of late. so close.

hugely appreciated,

- james

Java == platform independence
XML == application independence
JXTA == network independence

Secure End-to-End Computing

Scott Violet wrote:
> On Thu, Sep 30, 2004 at 10:07:13AM -0700, James Todd wrote:
>
>>Thx Scott.
>>
>>I should've added, I'm using version 1.4.2_04.
>>
>>Further the JXEditorPane I'm working with is not editable. I'm not sure if
>>this applies or not. The single method I'm using to (optionally) adjust the
>>ScrollBar is:
>>
>> sb.getViewport().setViewPosition(p);
>
>
> Even better. That means you're not invoking scrollRectToVisible so
> that if you put a breakpoint in scrollRectToVisible you'll be able to
> see why it's getting called.
>
>
>>where p is a Point and was evaluated just prior to adding the text.
>>
>>It is really odd that the code works under the jdnc-incubator (trivial stand
>>alone) yet seems to always scroll to end when embedded within a larger app
>>although I'm using JXFrame and the panel is roughly equivalent.
>
>
> That's for sure!
>
>
>>That aside, I will try to work in your suggestions.
>>
>>
>>>You're listener is notified first, if you consume the event than
>>>JXEditorPane won't process the key event.
>>
>>I assume you mean KeyListener?
>
>
>
> Yep.
>
>
>>If so, I've implemented the following
>>first attempt which echos to the command line yet still inserts a
>>newline.
>>
>> this.htmlEditor.addKeyListener(new KeyAdapter() {
>> public void keyPressed(KeyEvent ke) {
>> if (ke.getKeyCode() ==
>> KeyEvent.VK_ENTER) {
>> System.out.println("enter");
>> }
>> }
>> });
>
>
> Try adding ke.consume().
>
> -Scott
>
>
>>I suspect I'm missing something really silly here. Late nighter, looking
>>at the code too long kind of thing.
>>
>>That aside, I'd love to get these two issues addressed as the remaining
>>UI work should be relatively straight forward.
>>
>>much appreciated,
>>
>>- james
>>
>>Java == platform independence
>>XML == application independence
>>JXTA == network independence
>>
>>Secure End-to-End Computing
>>
>>
>>Scott Violet wrote:
>>
>>>On Thu, Sep 30, 2004 at 04:10:54AM -0700, James Todd wrote:
>>>
>>>
>>>>I have introduced a bit of code under:
>>>>
>>>> jdnc-incubator/src/java/org/jdesktop/jdnc/incubator/gonzo/editor
>>>>
>>>>With the goal being to adjust the JXEditorPane's scrollbar iff the
>>>>scrollbar
>>>>is at the end/maximum position, otherwise leave it in the current
>>>>position.
>>>>The implementation strategy basically captures the viewport position just
>>>>prior to appending the new text. if the position is not at the end/maximum
>>>>then the viewport is adjusted under a EventQueue.invokeLater() thread.
>>>>
>>>>The code appears to work fine in the standalone app (ie incubator) but
>>>>when
>>>>included within a larger Swing application (myjxta2.jxta.org) it fails.
>>>>
>>>>Any ideas?
>>>
>>>
>>>I suspect you are fighting with DefaultCaret. The text components, by
>>>way of DefaultCaret, try to make sure the location of the caret is
>>>visible and use scrollRectToVisible for that. It's possible you're
>>>doing a scrollRectToVisible, and then the text components are also
>>>doing a scrollRectToVisible. To verify this is what's happening I
>>>would override scrollRectToVisible and see who is calling it.
>>>
>>>
>>>
>>>>While I'm at it, any pointers on how best to capture and consume (vs
>>>>propogate)
>>>>a enter key press event? By adding a KeyListener to my JXEditorPane I can
>>>>see
>>>>when the key is pressed but I'm not sure how best to prevent the kestroke
>>>>from
>>>>getting processed by the underlying document.
>>>
>>>
>>>You're listener is notified first, if you consume the event than
>>>JXEditorPane won't process the key event.
>>>
>>> -Scott
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
>>>For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
>>For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

James Todd

This looks to have been my error as some earlier "viewport" calculcation
code we left in place that conflicted with the new strategy. It looks like
things are working fine now, on JRE 1.5.

Thx for the help,

- james

Java == platform independence
XML == application independence
JXTA == network independence

Secure End-to-End Computing

James Todd wrote:
>> Even better. That means you're not invoking scrollRectToVisible so
>> that if you put a breakpoint in scrollRectToVisible you'll be able to
>> see why it's getting called.
>
>
> will do.
>
>>> I assume you mean KeyListener?
>
>
> ahhh, much appreciated. i hit a mental block.
>
> that scroller issue is consuming my mind as of late. so close.
>
> hugely appreciated,
>
> - james
>
> Java == platform independence
> XML == application independence
> JXTA == network independence
>
> Secure End-to-End Computing
>
> Scott Violet wrote:
>
>> On Thu, Sep 30, 2004 at 10:07:13AM -0700, James Todd wrote:
>>
>>> Thx Scott.
>>>
>>> I should've added, I'm using version 1.4.2_04.
>>>
>>> Further the JXEditorPane I'm working with is not editable. I'm not
>>> sure if
>>> this applies or not. The single method I'm using to (optionally)
>>> adjust the
>>> ScrollBar is:
>>>
>>> sb.getViewport().setViewPosition(p);
>>
>>
>>
>> Even better. That means you're not invoking scrollRectToVisible so
>> that if you put a breakpoint in scrollRectToVisible you'll be able to
>> see why it's getting called.
>>
>>
>>> where p is a Point and was evaluated just prior to adding the text.
>>>
>>> It is really odd that the code works under the jdnc-incubator
>>> (trivial stand
>>> alone) yet seems to always scroll to end when embedded within a
>>> larger app
>>> although I'm using JXFrame and the panel is roughly equivalent.
>>
>>
>>
>> That's for sure!
>>
>>
>>> That aside, I will try to work in your suggestions.
>>>
>>>
>>>> You're listener is notified first, if you consume the event than
>>>> JXEditorPane won't process the key event.
>>>
>>>
>>> I assume you mean KeyListener?
>>
>>
>>
>>
>> Yep.
>>
>>
>>> If so, I've implemented the following
>>> first attempt which echos to the command line yet still inserts a
>>> newline.
>>>
>>> this.htmlEditor.addKeyListener(new KeyAdapter() {
>>> public void keyPressed(KeyEvent ke) {
>>> if (ke.getKeyCode() ==
>>> KeyEvent.VK_ENTER) {
>>> System.out.println("enter");
>>> }
>>> }
>>> });
>>
>>
>>
>> Try adding ke.consume().
>>
>> -Scott
>>
>>
>>> I suspect I'm missing something really silly here. Late nighter, looking
>>> at the code too long kind of thing.
>>>
>>> That aside, I'd love to get these two issues addressed as the remaining
>>> UI work should be relatively straight forward.
>>>
>>> much appreciated,
>>>
>>> - james
>>>
>>> Java == platform independence
>>> XML == application independence
>>> JXTA == network independence
>>>
>>> Secure End-to-End Computing
>>>
>>> Scott Violet wrote:
>>>
>>>> On Thu, Sep 30, 2004 at 04:10:54AM -0700, James Todd wrote:
>>>>
>>>>
>>>>> I have introduced a bit of code under:
>>>>>
>>>>> jdnc-incubator/src/java/org/jdesktop/jdnc/incubator/gonzo/editor
>>>>>
>>>>> With the goal being to adjust the JXEditorPane's scrollbar iff the
>>>>> scrollbar
>>>>> is at the end/maximum position, otherwise leave it in the current
>>>>> position.
>>>>> The implementation strategy basically captures the viewport
>>>>> position just
>>>>> prior to appending the new text. if the position is not at the
>>>>> end/maximum
>>>>> then the viewport is adjusted under a EventQueue.invokeLater() thread.
>>>>>
>>>>> The code appears to work fine in the standalone app (ie incubator)
>>>>> but when
>>>>> included within a larger Swing application (myjxta2.jxta.org) it
>>>>> fails.
>>>>>
>>>>> Any ideas?
>>>>
>>>>
>>>>
>>>> I suspect you are fighting with DefaultCaret. The text components, by
>>>> way of DefaultCaret, try to make sure the location of the caret is
>>>> visible and use scrollRectToVisible for that. It's possible you're
>>>> doing a scrollRectToVisible, and then the text components are also
>>>> doing a scrollRectToVisible. To verify this is what's happening I
>>>> would override scrollRectToVisible and see who is calling it.
>>>>
>>>>
>>>>
>>>>> While I'm at it, any pointers on how best to capture and consume
>>>>> (vs propogate)
>>>>> a enter key press event? By adding a KeyListener to my JXEditorPane
>>>>> I can see
>>>>> when the key is pressed but I'm not sure how best to prevent the
>>>>> kestroke from
>>>>> getting processed by the underlying document.
>>>>
>>>>
>>>>
>>>> You're listener is notified first, if you consume the event than
>>>> JXEditorPane won't process the key event.
>>>>
>>>> -Scott
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
>>>> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
>>> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
>> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net