Auto scrolling JTextAreas

Hi,
I am having an infuriating problem with my JTextArea which hopefully someone can help me with.
On my GUI I have a JTextArea in a JScrollPane which is uneditable as it
is there purely to give the user feedback. The user presses a button
and the program happily does its thing creating datafiles and other
such things and all the while telling the user what it is up to.
The code I use to update the display is this:
public void updateText(String str)
    textarea.append(string + "\n");
    textarea.paintImmediately();
    textarea.scrollRectToVisible(textarea.modelToView(
                      textarea.getDocument().getLength());
}This works fine until the text reaches the bottom of the JTextArea
because what ever the last line of text is, it gets repeated evertime
it scrolls until the program stops updating the display at which point
the text changes to what it should be. So for example, if the last text
was "This is rubbish" before it starts scrolling then the
display would look like this...
This is rubbish
This is rubbish
This is rubbish
This is rubbish....(and so on until the end where it changes to the proper text).
One thing I have noticed is that the last line in the JTextArea before
scrolling starts has about the bottom two rows of pixels missing from
the text, could this be causing the scrolling to mess up. I have tried
making the JTextArea double buffered and swapping the order of the
scrolling and the paintImmediatly.
I am really stuck and have searched through the forums trying all the
usual suggestions for scrolling such as setting the caret position but
this seems to be the only one that make the JTextArea scroll, albeit
with a messed up display.
Please can someone help me, this is really bugging me. (No pun intended).
Cheers Jim.

Check this code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class Test extends JFrame implements ActionListener
     static int nCount = 0;
     JTextArea m_areaTest = null;
     JButton m_btnTest = new JButton("Add");
     public Test()
          m_areaTest = new JTextArea(10,30);
          JScrollPane scrollTest = new JScrollPane(m_areaTest);
          m_areaTest.setLineWrap(true);
          getContentPane().setLayout(new FlowLayout());
          getContentPane().add(scrollTest);
          getContentPane().add(m_btnTest);
          m_btnTest.addActionListener(this);
          addWindowListener(new WindowAdapter()
               public void windowClosing(WindowEvent e)
                    dispose();
                    System.exit(0);
     public static void main(String args[])
          System.out.println("Starting CopyPaste...");
          Test mainFrame = new Test();
          mainFrame.setSize(400, 400);
          mainFrame.setTitle("CopyPaste");
          mainFrame.setVisible(true);
     public void actionPerformed(ActionEvent e)
          if(e.getSource() == m_btnTest)
               m_areaTest.append("This is rubbish"+ nCount+ "\n");
               nCount++;
               //m_areaTest.paintImmediately();   
               //bm_areaTest.scrollRectToVisible(m_areaTest.modelToView(textarea.getDocument().getLength()));
}regards
Praveen

Similar Messages

  • Text - Auto Scroll Function

    Does my iPad have an  Auto Scroll   for Safari?
    Is there a "hidden" feature that I can use for reading a text with Safari?
    An automatic scroll (activated by an command) would be a comfortable function.
    I don´t want to use an App.
    Thanks

    Tap and slide up to scroll. Tap and flick up to move faster.
    There is no way I know off to have the screen automatically scroll.
    The iPad has many security features to prevent malware attacks. One of these is called Sandboxing. This keeps each app in its place and prevents apps from altering the system resources or other apps. So no other app will provide the auto scroll functionality to Safari.
    You can make suggestions to Apple here:
    http://www.apple.com/feedback/

  • Auto-scrolling of list view in Finder windows sometimes doesn't work

    I've noticed a minor bug in 10.4 that doesn't seem to show up in 10.3.9, and I thought I'd comment on it here because it's mildly annoying, and I'm not sure that anyone at Apple is aware of the issue.
    My Pictures folder is pretty large -- I have over 6,000 items in it, some of which are themselves folders. I've got this folder set to list view. My typical usage pattern is to open a Finder window for my Pictures folder, start typing the first few characters of a file name, and then search from there. In 10.4.3 and later (up to and including 10.4.6 as of this writing), if the file in question is outside the viewport of the Finder window, the thumb on the scrollbar will jump to the correct location, but the actual viewport won't scroll to match; therefore, the file that gets highlighted isn't visible.
    The work-around is to manually scroll the contents of the window so that I'm "closer" to the file I'm looking for; alternately, I can type characters to get the ball rolling, and then hit the up or down arrow key a couple times (once won't do the trick) which will force the viewport to jump to the correct scroll location. Using this second method, I then have to move the selection back to the file, which is annoying since it's forcing me to use extra keystrokes.
    Interestingly enough, if I am careful and click on the scrollbar thumb without moving it too much (after typing the first few characters of the filename I'm looking for), the viewport will usually "snap to" the appropriate position. This suggests that the logic to auto-scroll the contents of a Finder window got subtly broken between Panther and Tiger. It just seems weird to me that the scrollbar thumb would jump without the viewport following suit automatically.
    This wasn't a problem in 10.3.9. I realize that we're being encouraged to use Spotlight and other search features, but since my pictures directory is already an alphabetic list view of files, why should I be forced to do a Spotlight search when I know what it is I'm after?
    Dual 2.0 GHz G5   Mac OS X (10.4.6)  

    I've been having the same problem (though I haven't looked at the console yet to verify the same exact error).
    There doesn't seem to be a situation that I can identify to cause the problem (i.e. waking from sleep mode), so it's difficult to reproduce consistently. The error seems to happen randomly. Last night I was getting the error every time I sent a single message. So I'd create and send a message, and then the next message I'd try to create or reply to, I couldn't. I'd have to quit Mail and start it again to gain functionality.
    When I do have the problem where the compose window isn't created when replying, I also can not start a new message, note, or forward a message. Basically, no new windows can pop up besides the windows that are already there in Mail. When I quit mail, every window I tried to create by replying, making a new message, or forwarding, appears in the draft folder, just before the program closes. Then, the next time I open Mail all the windows appear that I tried to create, with no text in them. Very strange. Looks like this poster has a similar problem.
    http://discussions.apple.com/thread.jspa?threadID=1197152&tstart=1020
    I'm curious if this is a bug, or something our machines just can't handle? I see that we all have very similarly spec'd PowerBooks.

  • How to get Auto scroll bar in a JSP?

    Hi Gurus,
    I have created a custom jsp page in a B2B application. How to get the auto scroll bar when page is exceeded than it can display?
    Is there any specific tag or div which is to be included to get this scroll bar?
    Thanks a lot in advance!!
    Regards,
    Lakshman.

    Hi Lakshman,
    You can include it in stylsheet and then use that class in your <body> or "div"  tag.
    the CSS command is
    overflow:auto;
    you can use like
    <body style="overflow: auto;"> or -- div style="overflow: auto;" 
    You can declare class in ".css" file
    #c1
    .c1
    <body id="c1>> or <div id="c1">
    <body class="c1>> or <div class="c1">
    You can use either "class" or "id" by adding it to "CSS" file and the use it to any JSP file or by direct aditing "Style" attirbute in tag.
    so when your content is longer then your screen browser will display scroll bar automatically.
    I hope this will help you.
    Thanks and Regards.
    eCommerce Developer
    Edited by: Ecommerce Developer on Jul 9, 2009 5:58 PM
    Edited by: Ecommerce Developer on Jul 9, 2009 5:59 PM

  • Just updated to Firefox 8, and my auto scroll on my touchpad no longer works. Any help?!

    Auto Scroll is checked in the advanced settings/options, but still not working. Arrow keys do work to scroll, but I do not use those....So far I'm not impressed with the updated firefox! Not liking the way it's set up!!

    Not sure whether this link can help:
    https://support.mozilla.com/en-US/questions/874268?s=trackpad+scroll&r=1&as=s

  • How to auto scroll a table to last row when using Active Data Service?  11g

    Hi all,
    Has anyone got any experience with the ADF Active Data Service?
    I am using an af:table in combination with the ADF Active Data Service and I want the table to scroll to the latest row when new data arrives.
    It is basically a simple setup:
    The value attribute of my table points to a bean that extends CollectionModel and implements ActiveDataModel. This works perfectly. A soon as I receive new data in my bean, the table is automatically updated (e.g. a new row is inserted). I use JDev version: 11.1.1.3
    The problem is that I can not get the scroll bar to move down to the last row automatically when new data arrives. The auto scroll only works for the client that actually performs a submit. In other words the person that submits the new data, will see his scrollbar move down, this is because I added the following code:
    RowKeySet rowkeysset = chatTableBinding.getSelectedRowKeys();
    rowkeysset.clear();
    rowkeysset.add(getRowKey());
    AdfFacesContext.getCurrentInstance().addPartialTarget(this.chatTableBinding);
    This does not work for the clients that receive the new data via the Active data model. Apparently the active data service partially refreshes the table, but not in such a way that it sets the selected row to the last row?
    My table definition:
    <af:table value="#{pageFlowScope.chatBean.instantMessagingChatwindowBean}" var="row"
    id="t1" columnStretching="last" rows="10"
    styleClass="AFStretchWidth" autoHeightRows="10" contentDelivery="immediate"
    horizontalGridVisible="false"
    verticalGridVisible="false"
    disableColumnReordering="true" displayRow="last"
    rowSelection="single"
    binding="#{pageFlowScope.chatBean.instantMessagingChatwindowBean.chatTableBinding}"
    inlineStyle="height:80px;">
    p.s.
    The table is used to show incoming chat message.
    I am building a chat client (taskflow) in a Webcenter application. The concept is similar of that presented by Lucas Jellemain in his blogpost on building a Google Talk Client http://www.oracle.com/technetwork/articles/jellema-googletalk-094343.html

    Dan,
    This is a thanks for posting your findings. You saved me quite some time.
    <af:selectBooleanCheckbox id="showOnlyActiveSubscriptions" selected="true"
    label="Show only active services:"
    value="#{servicePortfolioBean.showOnlyActiveSubscriptions}"
    autoSubmit="true" />
    <af:table binding="#{servicePortfolioBean.serviceTable}" ...
    partialTriggers="showOnlyActiveSubscriptions">
    Of course, when I add a "ValueChangeListener" to the selectBooleanCheckbox, the PPR stops working. :( I wonder why?

  • Auto scrolling dynamic text field(news ticker)

    > This message is in MIME format. Since your mail reader
    does not understand
    this format, some or all of this message may not be legible.
    --B_3272625483_2679871
    Content-type: text/plain;
    charset="US-ASCII"
    Content-transfer-encoding: 7bit
    Does anyone know how to make a scrollable dynamic text field
    scroll on its
    own and also with user interaction?
    Thanks in advance for your help.
    Bill
    --B_3272625483_2679871
    Content-type: text/html;
    charset="US-ASCII"
    Content-transfer-encoding: quoted-printable
    <HTML>
    <HEAD>
    <TITLE>Auto scrolling dynamic text field(news
    ticker)</TITLE>
    </HEAD>
    <BODY>
    <FONT FACE=3D"Verdana, Helvetica, Arial"><SPAN
    STYLE=3D'font-size:12.0px'>Does =
    anyone know how to make a scrollable dynamic text field
    scroll on its own an=
    d also with user interaction?<BR>
    <BR>
    Thanks in advance for your help.<BR>
    <BR>
    Bill</SPAN></FONT>
    </BODY>
    </HTML>
    --B_3272625483_2679871--

    I found this:
    http://www.kirupa.com/developer/mx/dynamic_scroller.htm
    I copied the actual scroller and put it in my .fla and it
    worked! Now if I can only figure out links in XML...

  • My auto-scroll 3rd button does not work in FireFox 3.6. It worked in previous FF versions.

    I have updated FireFox. My auto-scroll 3rd button now does not work in this version, 3.6 I have updated my mouse and checked the TOOLS "Use auto-scroll"... still it does not work.
    I need my equipment to work. PLEASE FIX

    I hate to sound like a broken record, DONE THAT ALREADY. _ _ _
    I've ALSO learned to reboot after an uninstall then manually delete any residue in said uninstalled program. I've also gone as far as REGISTER searching for program residue and deleting that WITH reboot of coarse to be sure nothing has gone wrong. _ _ _ NEXT suggestion? I suggest FireFox fix there software. _ _ _ BY-THE-WAY,... I have also gone through my mouses buttton choices for my #5 button. Everything works but the "Auto-Scroll". One tab down/up/right/left works, one page down/up/left/right works. _ _ _ I used recently tried and successfully used the Auto-Scroll in Netscape, Opera, My Browser, Ace Browser, Chrome, and 2 others that escape my memory. _ _ _ PLEASE READ and understand this. >>> It's FireFox's software that is stopping this, not my mouse or PC.

  • How do you enable Auto Scroll in a sequence pane, and MIDI devices?

    Hello,
    I am just getting used to Garage Band for the first time. I am finding that Garage Band is much easier to deal with than Mark Of the Unicorn from a musical standpoint.
    I am now converting my many MIDI sequences to GB. I have run into these three issues that I cannot seem to figure out.
    1. I have both the "Main Secuence" pane and the "Piano Roll/Score" pane arranged vertically. But the Secuence pane auto scrolls, as the timing progresses, but the "Piano Roll/Score" pane does not. How do I get these two windows to enable/disable auto scroll?
    2. How do I select from a starting bar to ending bar, for a given track, coping it, and pasting it to another track in the another track's sequence point?
    3. How do I add other MIDI decices that I have pysically connected, and assign specific tracks to these physical MIDI divices and their defined Timbers?
    Thanks in Advance.
    Jeff Cameron

    Thank you very much, Cristoph!
    With your help, you have answered both questions 1 and 3.
    Concerning question 2, I can see that when I click on the track header, the entire track is selected, but I am trying to physically select from one bar to another in that track.
    I've tried clicking on the start bar and draging to the end and releasing. The whole track is still selected.
    I've tried holding down the Shift key and doing the same. Still the whole track is still selected.
    I guess I am missing the basics of marking and selecting the start and end point from within a basic track.
    I'm already much farhter along with your help, and I appreciate your help, very much!
    Jeff Cameron
    (More a computer geek than a musician.)

  • Mail Drag and Drop to mailboxes not auto-scrolling

    When dragging a mail message to the sidebar and the mailbox I want to drag it to is not in sight, on earlier OSes, I used to be able to drag and hold to the top or bottom of the sidebar and it would auto-scroll so I could drop the message where I wanted. On Yosemite, no auto-scrolling happens. Is this just me or are other experiencing the same problem and/or does someone have a solution?

    beezaman,
    I also experience this issue. If I turn off or Hide if you will the Favorites Bar and the Toolbar then I'm able to drag a file to scroll up or down in the sidebar.  As I know hiding the toolbars isn't something many people would want to do, I would encourage sending Apple feedback about this issue. You can do so at the following link: https://www.apple.com/feedback/macosx.html
    For me a solution for now would be to use the scroll whilst dragging feature of the trackpad. Click and drag a message over the sidebar and then whilst still holding down the left click I can scroll up or down using the trackpads two finger scroll.
    Hope that helps,
    Weston

  • Need debugging help: Why is JScrollPane auto-scrolling?

    I'm trying to figure out why when I double-click on a cell within a JTable that's wrapped in a JScrollPane in order to open up another window, the JScrollPane automatically scrolls to the top.
    Even when I update the double click operation to simply call setSelected(false), the JScrollPane still automatically scrolls to the top.
    I added myself as a change listener to the scroll pane's row header view port, and captured the following stack trace.
    I'm having trouble debugging exactly what is causing the following chain of events to fire. If I try to put a debug breakpoint on a method like EventQueue.invokeLater() that's probably initiating the following chain of events, I can't even get back to my application window from my IDE without having to dismiss all of the breakpoints that are reached.
    If I try to follow through from the double-click to the actual JScrollPane auto-scroll, I get lost in a maze of Swing events that I can't navigate out of.
    Any suggestions on how to appropriately debug this would be greatly appreciated.
    Thanks,
    Mike
    rowHeaderViewPort stateChanged fired
    chgEvent == javax.swing.event.ChangeEvent[source=javax.swing.JViewport[,1,21,0x329,invalid,layout=javax.swing.ViewportLayout,alignmentX=null,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=0,height=0],isViewSizeSet=false,lastPaintPosition=,scrollUnderway=false]]
    chgEvent source == javax.swing.JViewport[,1,21,0x329,invalid,layout=javax.swing.ViewportLayout,alignmentX=null,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=0,height=0],isViewSizeSet=false,lastPaintPosition=,scrollUnderway=false]
    java.lang.Exception: stack trace
         at MyForm$2.stateChanged(MyForm.java:192)
         at javax.swing.JViewport.fireStateChanged(JViewport.java:1341)
         at javax.swing.JViewport.setViewPosition(JViewport.java:1096)
         at javax.swing.ViewportLayout.layoutContainer(ViewportLayout.java:179)
         at java.awt.Container.layout(Container.java:1020)
         at java.awt.Container.doLayout(Container.java:1010)
         at java.awt.Container.validateTree(Container.java:1092)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validate(Container.java:1067)
         at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

    Thanks for your response. I examined the code and nowhere that I can see is it calling either of those two methods.
    At some point, it looks like something within my code or in the UI frameworks that I'm using is invalidating my JScrollPane. I'm having a very difficult time, though, tracking down exactly which component is causing that invalidation.
    Short of writing my own JScrollPane so that I can capture the stack trace of calls to invalidate(), does anyone have any suggestions for debugging this further? I tried to use a conditional breakpoint in Eclipse 2.1.3 (Component.invalidate() where the Component is an instance of JScrollPane), but my breakpoint is never being executed.
    Thanks,
    Mike

  • Why does the history/library window auto-scroll away from the previous point in the library?

    When in Firefox 23.0's history/library window when I am browsing it will auto-scroll to the top of "Today" page making it frustrating and difficult to browse. I do not seem to recall this being the case before. I disabled "auto-scroll" in options and this has not remedied the problem.

    Hello,
    Try disabling graphics hardware acceleration. Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches.
    You might need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
    Then perform these steps:
    *Click the orange Firefox button at the top left, then select the "Options" button, or, if there is no Firefox button at the top, go to Tools > Options.
    *In the Firefox options window click the ''Advanced'' tab, then select "General".
    *In the settings list, you should find the ''Use hardware acceleration when available'' checkbox. Uncheck this checkbox.
    *Now, restart Firefox and see if the problems persist.
    Additionally, please check for updates for your graphics driver by following the steps mentioned in the following Knowledge base articles:
    * [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]
    * [[Upgrade your graphics drivers to use hardware acceleration and WebGL]]
    Did this fix your problems? Please report back to us!
    Thank you.

  • Ereader and auto scroll

    Is there an ereader for the Iphone that supports auto scroll?

    http://www.google.com do a search.

  • Why does snagit auto scroll not work in firefox version 3.6.8 and can it be fixed

    I have used Snagit v9.1 with Firefox for a long time through many updates but when I updated to Firefox version 3.6.8 the auto scroll stoped working, I did go back to an earlier version of Firefox and it worked OK.

    [http://techsmith.custhelp.com/cgi-bin/techsmith.cfg/php/enduser/std_adp.php?p_faqid=2353&p_created=1264531389&p_sid=htZsTh8k&p_accessibility=0&p_redirect=&p_lva=&p_sp=cF9zcmNoPSZwX3NvcnRfYnk9JnBfZ3JpZHNvcnQ9JnBfcm93X2NudD0xNTA5LDE1MDkmcF9wcm9kcz0mcF9jYXRzPSZwX3B2PSZwX2N2PSZwX3NlYXJjaF90eXBlPWFuc3dlcnMuc2VhcmNoX25sJnBfcGFnZT0x&p_li=&p_topview=1 Read these steps] from the Snagit support website.

  • How scroll through a list of items in list box with code in C# winforms to create auto scrolling

    I am new to programming and I have been tasked to create a form to display information in list box controls on a big screen. The list boxes have to show all data by auto scrolling through all data row by row then start again at the top once it has displayed
    all data. Is there a way to do this automatically in code using a timer? I look all over the web and have not found any way to do this in win win forms. Is it possible?
    Thanks 

    Here's the c# code
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    namespace WindowsApplication13
    public partial class Form1 : Form
    System.Timers.Timer timer = new System.Timers.Timer();
    int position = 0;
    public delegate void delegateUpdateListbox();
    public Form1()
    InitializeComponent();
    private void Form1_Load(object sender, EventArgs e)
    timer.Interval = 1000;
    timer.Enabled = true;
    timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    position += 1;
    if (position == listBox1.Items.Count)
    position = 0;
    delegateUpdateListbox deleg = new delegateUpdateListbox(updateListbox);
    this.Invoke(deleg);
    void updateListbox()
    listBox1.SelectedIndex = position;
    As long as the listbox's SelectionMode is set to "One" (the default), you don't have to do anything to un-select the previous item.
    For your secnd question, the code inside the timer checks whether the position is the same as the length of the contents of the listbox and resets its value to zero, so that the selection will go back to the first item in the list.

Maybe you are looking for

  • Active Job List

    Hi, I want to check if a particular job is in active status or not in abap code. Please, help. Regards, Alok Mehta

  • HT1947 Is the current Remote app compatible with iPod Touch 4.2.1?

    This KB article says so, but iTunes will not load the current version of Remote onto a 2g 4.2.1 iPod Touch. http://support.apple.com/kb/HT1947 I unfortunately had to restore my 2nd Gen iPod Touch, and in doing so, iTunes indicated that several existi

  • About N73 Music Edition

    Hails to everyone! I hope this is not a boring topic to start with I am considering to buy an N73 Music Edition, and I wanted to learn your personal opinions about the issue. Would you recommend/suggest buying one? Or would you advice to go with othe

  • Serial baud rate vs. high speed CAN

    The bottleneck in my current app is the serial writes at 115200, to a custom device.  The program dramatically improves in speed as the baud rate is increases.  If i remove the serial write and read, the program loop time improves from 100 to 2000htz

  • Region - Display only on form layout page

    Hi, 1) I have defined regions on table-form layout style. How ever I want the regions to be displayed only on the Form layout and not on the table layout page that has the search functionality. Is there a way to hide the regions on the search page? 2