JScrollPane Scroll Position

Tried posting this in the newbie section with no luck....
I created a class extending a JScrollPane that encompasses a JTextPane. The method below appends some text to the current JTextPane with a certain color (this part works fine). What I am also trying to do is force the JScrollPane to keep focus at the bottom after the append if it was there before the append. Now I am running into trouble.
The code can determine fine if the scroll pane is at the end, but after the append, it sometimes prematurely puts the pane at the end again; i.e. the method is telling the scroll pane to go to the end before the text pane and/or scroll pane have finished updating their size. Thus, the scroll pane is moved to the bottom, then the text and scroll panes resize, and the scroll pane is no longer at the bottom.
It seems that this problem occurs when the text appended is multiple lines, in which case it appears that the panes are resized multiple times- the scroll bar is positioned correctly after the first resize, but subsequent resizings sometimes occur after I reposition the scroll bar to the current "end" (which then changes).
I've tried validating both panes to force them to update before repositioning the scroll bar, but this does not seem to stop the problem (although it may help).
Does anyone know how to correct this problem? I'm still guessing that something (perhaps the doc?) is not fully updated by the time I reposition the scroll bar. If this is the problem, any suggestions on how to force the document to be updated before playing with these GUI panes? If possible, I prefer not to use a timer or sleep a thread to wait for this updating.
Of course, if you know of existing methods/settings that help with this, please tell. I didn't manage to find anything in the API's that gave me what I want, but I've been known to overlook things from time to time ;)
Again, this is a method in a class extending JScrollPane.
textPane is the JTextPane embedded in the scroll pane.
doc is the JTextPane document.
public synchronized void append(String appendString, Color textColor)
     JScrollBar scrollBar;
     BoundedRangeModel rangeModel;
     boolean isMaxed;
     scrollBar = this.getVerticalScrollBar();
     rangeModel = scrollBar.getModel();
     isMaxed = ((rangeModel.getValue() + rangeModel.getExtent())
                         == rangeModel.getMaximum());
          // check if the scroll bar is at the bottom
     SimpleAttributeSet textAttributes = new SimpleAttributeSet();
     StyleConstants.setForeground(textAttributes, textColor);
     try
          doc.insertString(doc.getLength(), appendString, textAttributes);
          // append the formatted string to the document
     catch(BadLocationException ex)
          System.out.println("Error writing to the text pane");
     if (isMaxed)
          textPane.validate();     //force the text pane to validate
          this.validate();    //force the scroll pane to update
          scrollBar.setValue(rangeModel.getMaximum() - rangeModel.getExtent());
          // The above line is sometimes called before the text and scroll panes
          // have finished updating.  The maximum and extent of the scroll bar
          // depend on the size of the document.

You are correct in your observation that the size of the JScrollPane is incorrectly reflected for the size of your newly appended document. I spent some time on this bug and eventually came up with the following solution:
textPane.addComponentListener( new ComponentListener(){
public void componentHidden(ComponentEvent e)
public void componentMoved(ComponentEvent e)
public void componentResized(ComponentEvent e)
JViewport vp = scrollPane.getViewport();
incoming.revalidate();
Rectangle visRect = vp.getViewRect();
Dimension viewDim = vp.getViewSize();
Rectangle rect = new Rectangle( 0, (int)(viewDim.getHeight() - visRect.getHeight()),
(int)visRect.getWidth(), (int)visRect.getHeight() );
vp.scrollRectToVisible( rect );
public void componentShown(ComponentEvent e )
This solution also has the side benefit of scrolling to the bottom when the JTextPane is resized by the user.

Similar Messages

  • JScrollPane - can you set scroll position?

    I have a JList loaded into a JScrollPane, and I call a method that highlights a row of the JList, but I can't figure out how to get the JScrollPane to scroll down.
    Is there a method where I can manually set the scroll position? I looked at the documentation online and didn't see anything like that.
    Thanks.
    -Mark

    You need to get a reference to the JScrollPane's JViewport
    myPane.getViewport();
    Then on the viewport you can call one of these.
    scrollRectToVisible(Rectangle contentRect)
    setViewPosition(Point p)
    Cheers,
    Rachel

  • How to play a symbol ONCE at a specific scroll position?

    Hello there,
    I was wondering if it's possible to trigger a symbol to play when a user scrolls past a specific scroll point just once?
    I've managed to create a trigger for a symbol which will fire at a specific scroll position but it fires multiple times (when the user continues to scroll)
    I tried using:
    '==' eqivalent to, so that it would only trigger at a certain scroll point, but this only triggers the symbol to play if the user uses their mouse scroll wheel and doesn't play if the user uses the window scrollbar.
    Here's my code (apologies if it's messy I only started learning JQuery a week ago):
    $(window).scroll(function() {
         var mySymbolObject = sym.getSymbol("rollHead");
          var y_scroll_pos = window.pageYOffset;
         var scroll_pos_test = 500;           
        if(y_scroll_pos > scroll_pos_test) {
              sym.$("rollHead").show();
              mySymbolObject.play(1000);
          if(y_scroll_pos < scroll_pos_test) {
       sym.$("rollHead").hide();
              mySymbolObject.stop();
    I know that the '.one' handler (if that's the correct term) can cause an event to trigger just once, but I can't seem to get it to work.
    Any help or advice would be much appreciated.
    Thank you very much.
    Jon
    P.S. I just want to say a MASSIVE thank you to Adobe for making Edge. It is an incredible tool and the fact that it is free makes it a million times better.

    Hello Mr Blix,
    I pretty much just copied and pasted what Elaine wrote.
    So, I went to my stage actions - clicked 'composition ready'
    And put in this:
    sym.setVariable("symbolPlayed", false);
    var mySymbolObject = sym.getSymbol("rollHead");
    $(window).scroll(function() {
        var y_scroll_pos = window.pageYOffset;
        var scroll_pos_test = 500;           
           if(y_scroll_pos > scroll_pos_test) {
    var symbolPlayed = sym.getVariable("symbolPlayed");
    if (!symbolPlayed) {
        sym.$("rollHead").show();
        mySymbolObject.play(1000);
        sym.setVariable("symbolPlayed", true);
    All you'd need to change for you own composition (if that's the right word) is to replace:
    var mySymbolObject = sym.getSymbol("rollHead"); - with your own symbol name.
    var scroll_pos_test = 500;  - with the position you want the event to trigger.
    sym.$("rollHead").show(); - with your own symbol name again.
    mySymbolObject.play(1000) - with the time on your symbol's timeline that you want it to play.
    I'm still learning JQuery and don't really understand how the 'SymbolPlayed' works, but I assure you it does.
    Here's a screengrab of my 'stage actions' code.
    Hope that helps!
    Jon

  • Opening a new link in a tab (contr+click or right click and open in new tab) causes ff to lose scroll position in first tab or main website, like google.

    Opening a new link in a tab (contr+click or right click and open in new tab) causes ff to lose scroll position in first tab or main window, like google.
    This does not happen when opening in a new window (shift+click).
    It was never a problem in older versions. I now have ff 3.6.17. I' afraid to install ff4 because everytime i do so (install e new version) something i liked dissapears or good add ons dont work anymore!
    I also don't like the fact that more and more of the adress barr is beïng used for crap i don't need. I'm a visual handicap and need all the space i can, just to read.
    Thanks for helping me out.

    To help other users find solutions, please return to this Thread and '''Sign-in''' to the forum with your Username and Password:
    click on '''"Solved It"''' next to the reply ABOVE that '''BEST''' solved your question
    '''DO NOT click "Solved It" next to this reply

  • Chart Error - scroller positions should be positive and integer

    <p>
    Hello Expert
    I have created a flash chart with two filters on the chart region.
    i) &lsquo;Select list with submit' ----- (:P23_TRC)
    ii) &lsquo;Radio button with submit' -----(:P23_IMPACTC)
    The chart should display as per the filters selection.
    However, I get the error message "<strong>scroller positions should be positive and integer</strong>", once, whenever I load this chart page for the 1st time in a new IE window.
    After I change the filter's value it will work perfectly fine.
    In filters default value is one value from respective filter list of value
    </p>
    <p>
    If I remove the filter conditions from chart query, it works perfectly without error.
    <u>Here are my chart series queries</u>
    select null link, V.LOB label, COUNT(TR) "Customer Care"
    from V_PROCESSTRACKING V
    Where V.ProcessArea like '%Customer Care%' and (V.TR = :P23_TRC) AND ((V.IMPACT = :P23_IMPACTC)OR (:P23_IMPACTC = 'ALL'))
    group by V.LOB
    order by V.LOB
    select null link, V.LOB label, COUNT(TR) "Sales"
    from V_PROCESSTRACKING V
    Where V.ProcessArea like '%Sales%' and (V.TR = :P23_TRC) AND ((V.IMPACT = :P23_IMPACTC)OR (:P23_IMPACTC = 'ALL'))
    group by V.LOB
    order by V.LOB
    <u>Customer XML</u>
    &lt;?xml version = "1.0" encoding="utf-8" standalone = "yes"?&gt;
    &lt;root&gt;
    &lt;type&gt;
    &lt;chart type="Stacked Horizontal 3DColumn"&gt;
    &lt;animation enabled="yes" appearance="size" speed="10" /&gt;
    &lt;hints auto_size="yes"&gt;
    &lt;text&gt;&lt;![CDATA[{NAME}, {VALUE}]]&gt;&lt;/text&gt;
    &lt;font type="Verdana" size="10" color="0x000000" /&gt;
    &lt;/hints&gt;
    &lt;names show="no"/&gt;
    &lt;values show="no" prefix="" postfix="" decimal_separator="." thousand_separator="," decimal_places="0" /&gt;
    &lt;arguments show="no" /&gt;
    &lt;column_chart column_space="3" block_space="12"&gt;
    &lt;border enabled="no" /&gt;
    &lt;block_names enabled="yes" placement="chart" position="left" &gt;
    &lt;font type="Verdana" size="10" color="0x000000" /&gt;
    &lt;/block_names&gt;
    &lt;/column_chart&gt;
    &lt;/chart&gt;
    &lt;workspace&gt;
    &lt;background enabled="yes" type="solid" color="0xffffff" alpha="0" /&gt;
    &lt;base_area enabled="no" /&gt;
    &lt;chart_area enabled="yes" x="215" y="50" width="705" height="500" deep="0"&gt;
    &lt;background enabled="no"/&gt;
    &lt;border enabled="yes" size="1"/&gt;
    &lt;/chart_area&gt;
    &lt;x_axis name="Line of Business" smart="yes" direction="horizontal" rotation="-90" position="left_center" &gt;
    &lt;font type="verdana_embed_tf" size="14" color="0x000099" bold="yes" align="center" /&gt;
    &lt;/x_axis&gt;
    &lt;y_axis name="No. of Process" smart="yes" position="center_bottom" &gt;
    &lt;font type="Verdana" size="14" color="0x000099" bold="yes" align="center" /&gt;
    &lt;/y_axis&gt;
    &lt;grid&gt;
    &lt;values /&gt;
    &lt;/grid&gt;
    &lt;/workspace&gt;
    &lt;legend enabled="yes" x="935" y="50"&gt;
    &lt;names enabled="yes"&gt;
    &lt;font type="Verdana" size="9" color="0x000000" bold="yes"/&gt;
    &lt;/names&gt;
    &lt;values enabled="no"/&gt;
    &lt;scroller enabled="no"/&gt;
    &lt;header enabled="no"/&gt;
    &lt;background alpha="0"/&gt;
    &lt;/legend&gt;
    &lt;/type&gt;
    #DATA#
    &lt;/root&gt;
    <strong>Help please!!!!! It's urgent</strong>
    Sagar
    </p>

    Hi Rima,
    I found the solution,
    My graph is dependent on the page items. What I found was when I load the page, item default value was displayed but it was not stored in the memory. Item value only gets stored in memory when the page is submitted.
    Line: -----
    Soultion : - Create a page level before header process and define the default value over here as well. This will resolve your error.
    Hopefully you understood what I am trying to explain. If not let me know and I will trying to put in picture and email you.
    Sagar

  • How to avoid blinking / moving of rows in a data grid when you restore the scroll positions

    By Default when an update is made on a data grid, it scrolls to top row. To avoid this when we save the vertical and horizontal scroll
    positions and restore the scroll positions after the update, it causes a blink in the grid (or moving / jumping) of rows. Is there a way to
    avoid this jumping of rows?
    In JavaScript this can be achieved by overriding the scrollToTop / OnLoad methods of datagrid to directly scroll to current scroll
    positions instead of top row. Is there a way to achieve similar feature in flex / actionscript?

    I am calling validateNow().. Also, using verticalScrollPosition to restore the scroller as in the link that you posted.. Reposition is working fine, But the bug filed is regarding BLINKING / JUMPING when this happens (i.e. this blinking is caused because after datagrid edit, during reload the scroller tries to move to  the top by default, then it repositions itself to current edited row as the verticalScrollPosition property is overridden ).. I have to get rid of this blinking.
    In Javascript it is dealt by overriding OnLoad method of datagrid to directly scroll to current scroll position instead of top row during reload so that there is no blinking.
    http://www.sencha.com/forum/showthread.php?13898-Is-there-any-way-to-keep-scroll-position- of-Grid-on-load
    Is there a way to achieve similar feature in flex?
    I am not sure what flex datagrid method to override.. Theres no method like load? What is the datagrid method that is called by default during reload (after datagrid edit) that causes the scroller to go to top?

  • Web page in iframe does not maintain scroll position on refresh in FF4

    I have a web page on my local drive which refreshes live sports commentary every minute in an iframe.
    In FF3.6.x the page in the iframe retained the scroll position of where I had moved to.
    In FF4 the page within the iframe goes back to the top so I now have to scroll down every time to where I want to read.
    I disabled all addins in FF4 and have tried this on different URLs but the page in the iframe still returns to the top.

    Similar problem running a 27" iMac only it occurs in Excel and inDesign. Hit the cell with the curser and the worksheet moves over to the right 7 or 8 cells away. Have to curser back to the cell quite frequently. This issue make the machine unusable when working with those two aps. Today I did the ultimate and completely reloaded Yosemite and the problem is still there.

  • Scroll Positions do not work if Scroll Policy is 'off'

    I am using flex SDK 3.3.0.4852
    I have a canvas with
    canvas.horizontalScrollPolicy = "off";
    canvas.verticalScrollPolicy = "off";
    This canvas has an image in it, and I set the horizontal and vertical scroll positions programitically.
    canvas.horizontalScrollPosition = canvas.maxHorizontalScrollPosition;
    canvas.verticalScrollPosition = canvas.maxVerticalScrollPosition;
    then I save the scroll values in an xml file, and then on reopening of the xml file.. I do the following
    canvas.addEventListener("creationComplete", setScrollPositions);
    and in the method setScrollPositions(event) i do the following again
    canvas.horizontalScrollPosition = canvas.maxHorizontalScrollPosition;
    canvas.verticalScrollPosition = canvas.maxVerticalScrollPosition;
    But unfortunately it does not show any change in the scroll positions visually, and the default scroll positions persists. Though if i call an alert
    Alert.show(canvas.verticalScrollPosition.toString()); //it does show me some value, e.g. 56
    Now if i only set horizontal and vertical scrollPolicy = "on" ... all works fine. But the problem is that I want to hide my scrollbars and there is no other way I can do it. So please if there is any solution to it or if there is any workaround, do let me know. Thanks.

    i'm having the same problem and i just got a brand new dell..when i hold down the left click over the up or down arrows, my songs in itunes only go down one line rather than scrolling up or down while im holding down the left click...any help is appreciated..

  • Accordion Widget not saving current scroll position

    Accordion widget saves scroll position in Firefox, however in
    IE7 the position gets reset to the center of Accordion Widget.
    Example. Select Alabama and then select Wisconsin to see
    effect.
    See www.Qualite1.com/contactUs.html

    Hi ghaug,
    This is due to the tabindex attribute that is on the
    top-level element of the accordion. Apparently when an element is
    focused in IE, it tries to make sure the top of that element is in
    view, so it is "conveniently" scrolling it into view for you.
    To prevent this behavior for accordions like yours that don't
    fit neatly into a single screen, you are going to have to remove
    the tabindex attribute from the top-level accordion element. If you
    still want/need keyboard navigation of your accordion, then you
    have to switch to using links in your accordion tabs. You can find
    an example here:
    http://labs.adobe.com/technologies/spry/samples/accordion/AccordionSample.html#EnablingKey boardNavigationWithLinks
    --== Kin ==--

  • Last page scroll position not remembered

    After getting search results in Google, I click on a subject, then when I click "back" it returns to the top of the previous page. It's like it doesn't remember where it was. One fix I found was to change cache-control in about:config. But I can't find it. Where is I located? Another fix is "Restore Scroll Position" does this work on ver 3.6.12 ?
    TIA

    It is usually easier to open the results in a new tab with a middle click on the link and close that tab with a middle click on that tab on the tab bar.
    For the Google website you can set your preferences on the Google.com page via the [http://www.google.com/preferences?hl=en Google Search settings] link at the top right.
    Results Window: Open search results in a new browser window.

  • How to get/set scrolling position in Frame?

    Hello!
    Help me please!
    I need to remember scrolling position of frame before it's reloading. And restore this position after reloading. How can I do it?
    I Use JDk 1.4.1
    Thanks beforehand!
    Denis.

    Have you tried the following:
    yourScrollPane.getVerticalScrollBar().getValue()
    yourScrollPane.getVerticalScrollBar().setValue(int)Sai Pullabhotla

  • ADF Treetable scrolling position resets to top on refresh

    I have a master details page with the following components.
    TreeTable with a Check Box on LHS  and TabbedPannel on RHS.
    So, users can select any row on the LHS and the corresponding details will be displayed on RHS in a new Tab. When user closes the Tab it will clear the Check Box on TreeTable.
    Issue is, when user is at last row of TreeTable when there are more rows (Scroll bar will be at last), and user closes the Tab on RHS side, I will be clearing the checkbox binding and refresh the treetable using PPR to reflect the same.
    This is causing the treetable  scroll bar to be reset to the top. And User lost the old position on needs to scroll down again.
    Can we control the Scroll bar position after PPR refresh (or)
    Can we just clear off the CheckBox selection (only one row) with out refeshing the whole treetable
    Environment:
    JDev Version : 11.1.1.6.2
    Component : ADF TreeTable with TreeModel binding (Not using BC)

    In my case, I am fine with disclosureState items. They do not collapse even after I remove the checkbox selection and refreshing the TreeTable component.
    Only issue is scrollbar is resetting to top.
    I can't use the disclosure event as they can do expandAll , select first compoenent scroll down and close the selection on RHS tab.
    Which will reset the LHS scrolling position to top.

  • Flex 4.6 Mobile Scrollbar optimisation prevents setting scroll position?

    Hi All,
    With the release of flex 4.6 , it appears the mobile version of the scroller has been optimised. Now the scroller defers creation of the scroll bar until the user interacts with the scroller.... Which all sounds good performance wise, faster page creation etc...
    But if I want to move the scroller position before the user has interacted with the object , IE to jump to particular position before they start scrolling, I'm not sure what to do. Orginally I would have done something like...myScroller.horizontalScrollBar.value = 100 ... but of course myScroller.horizontalScrollBar is now null.
    Am I missing something - is there another way.
    J

    Ok found a work around...
    I extended the scroller class and added a couple of functions like...
    public function scrollerCreateHScrollBar():void
        if ( !this.horizontalScrollBar && this.horizontalScrollBarFactory)
                this.horizontalScrollBar = HScrollBar(this.createDynamicPartInstance("horizontalScrollBarFactory"));
                Group(this.skin).addElement(this.horizontalScrollBar);
                partAdded("horizontalScrollBar", this.horizontalScrollBar);
    then called to create teh scoll bars when I want them...
    Hurra.
    J

  • Get scroll position

    hey,
    i'm using jdeveloper11g and I use a RichTable to display data of a ViewObject. The data associated with the view object changes and i need to update RichTable accordingly. However, as I update using Poll the scroll position of the table is changed to top most position. What i need is to preserve the scroll position even after the refresh...any hints would be a gr8 help
    thanx

    That's not as easy as it sounds :-(
    As far as I know there is no method to get the scroll bar position itself.
    The problem is to get hold of the position the iterator is in when the poll event occurs.
    You execute the underlying query again to show new data. Depending on the query (i.e. sort) the result might be different after the refresh. The user might be confused about the new result, but I guess you thought out this.
    You can play with this EL #{bindings.YourView.iteratorBinding.rangeStart}and save the value before you re execute the query and after execution set the position back.
    Timo
    P.S.:
    I did not test this with scrollable views (which are the preferred views to use with faces). so you might allays get 0 as result. In this case you can try to save the current record (if you have one selected) and go back to this record after refresh.
    Edited by: Timo Hahn on 29.09.2009 14:14

  • Getting scroll position

    I can read and write the zoom level of a document (doc.zoom).  I can scroll to a specific point in the document (doc.scroll).  Bu I can't read the current scroll position.  Is there a way around this.
    The scenario:
         I have 24 pdf documents each with a single page containing a picture.
         Each picture was taken with a fixed camera - one picture for each hour of the day.  So the pictures are of the same thing - just separated taken at different times.
         On the 1:00 am picture I see something I want to examine more closely so I zoom and scroll to a particular portion of the picture.
         Now I want to see the same area on the 2:00 am picture.  I can read open the 2:00 am picture and zoom to the same zoom level (by reading the zoom property of the 1:00 am document).
         But how do I get the the 2:00 am document to scroll to the same position as the 1:00 am document if I can't read the scroll position of the 1:00 am document?
    My actual issue is more complex than this scenario but this illustrates the question.

    In any case viewState only works with embedded PDF - which is not the scenario I have.
    In some respects I want something like synchronized scroll but I am dealing with multiple documents.  I open one document and zoom/pan to a particular spot.  Then I want to open another document with the same zoom and pan.  I will select the other document from a list which could have many dozens of documents.  It is impractical to open all the documents at the same time.
    One possibility I have not considered yet would be use Bookmarks.  Bookmarks store the zoom level but I don't know if they store the pan.
    What I want is something like the center point of the current view.  This value could be passed to doc.scroll.  Is there a parameter that gives the coordinates of the document view (not the screen coordinates - but the document coordinates?  I could calculate the point necessary for doc.scroll from thse coordinates.

Maybe you are looking for

  • Home sharing not working between itunes and apple tv, I've read all help articles I could find... still nothing

    Hey there! Here's every detail of the problem: 1- My iTunes (10.5.2) doesn't give me any options for apple tv in any menu. Some troubleshooting article I remember said something like «go to Settings - Apple TV - Always Search for Apple TVs» or someth

  • Audio Sync

    Is it possible to hear audio playing through speakers hooked up to built-in audio that is in synch with video playing through firewire on a NTSC monitor? The only way I seem to be able to get audio to sync with the monitor is to use the monitors spea

  • Vertical Text in PDF using CFDOCUMENT

    I am using font tag in a CSS file to layout a table header using vertical text. In HTML, the vertical text looks fine. However, when I convert the table to a pdf using <cfdocument>, the vertical text is displayed as horizintal text and does not follo

  • How do i set up apple mail on my iPad

    how do i set up apple mail on my iPad, operating on the latest version of OS Regards [email protected]

  • VAT Registration Number & VAT code & VAT rate

    Hello Gurus, I am trying to find out, 1) How can I retrieve (either via a table lookup or function module) a list of VAT codes & VAT rates by        Legal Entity and Country? 2) How can I retrieve (either via a table lookup or function module) the VA