Autoscroll

Hi,
Can anybody help me in doing autoscroll in swing application.
I am using the follwing code but it does not work perfectly. Sometimes it does not scroll up or down properly.
<code>     
          if(!scrollPane.getBounds().contains(focusedPanel.getBounds())) {
               if((scrollPane.getVerticalScrollBar().getValue() + scrollPane.getViewportBorderBounds().height) < focusedPanel.getBounds().y) {
                    scrollPane.getViewport().setViewPosition(new Point(0, focusedPanel.getBounds().y));
                    scrollPane.revalidate();
                    scrollPane.repaint();
               }else if(focusedPanel.getBounds().y < (scrollPane.getViewportBorderBounds().height - scrollPane.getVerticalScrollBar().getValue())) {
                    scrollPane.getViewport().setViewPosition(new Point(0, focusedPanel.getBounds().y));
                    scrollPane.revalidate();
                    scrollPane.repaint();
</code>
Here scrollPane is the component having scrollbars and focusedPanel is the component which has to be made visible after scrolling.
Thanks in advance.

try:
EventQueue.invokeLater(new Runnable()
    public void run()
        // scrollToRect...
});Jim

Similar Messages

  • Up/Down Arrow keys do not perform their function on SOME websites or at SOME times, on other websites and at other times these keys work fine, updated firefox, restarted computer. turned off cursor key option in Advanced tab, using autoscrolling option.

    Up/Down Arrow keys do not perform their function on SOME websites or at SOME times, on other websites and at other times these keys work fine, updated firefox, restarted computer. turned off cursor key option in Advanced tab, using autoscrolling option.

    You may have switched on [http://kb.mozillazine.org/accessibility.browsewithcaret caret browsing].
    You can press press F7 (on Mac: fn + F7) to toggle caret browsing on/off.
    See http://kb.mozillazine.org/Scrolling_with_arrow_keys_no_longer_works
    * Tools > Options > Advanced : General: Accessibility: [ ] "Always use the cursor keys to navigate within pages"

  • When using the same Firefox profile in Ubuntu 12.04 and Windows 8.1, how can I keep autoscrolling enabled in Firefox for Linux?

    I access the same Firefox profile in Ubuntu 12.04 and Windows 8.1 (Windows fast startup disabled). I have the newest version of Firefox (26.0) on each system.
    Every time I launch Firefox in Ubuntu after using the profile in Windows, I notice that autoscrolling is disabled. So I have to manually enable it every time after using my profile in Windows.
    Conversely, every time I launch Firefox in Windows after using the profile in Ubuntu, I'm asked whether I would like to set Firefox as my default browser. I choose "No", first making sure that there is no check mark next to "Always perform this check when starting Firefox". I have to do this every time after using my profile in Ubuntu, despite the fact that if I check my preferences in either OS, "Always check to see if Firefox is the default browser on startup" is not enabled. Note that Firefox is my default browser in Ubuntu but not in Windows, but I have no need for Firefox to check whether it's the default every time it starts in either OS.
    I don't know whether these problems are related, but it seems likely that they are. Is there a way that I can keep these settings constant, so they don't reset every time I switch operating systems?

    I'm sure that when I close the browser in either OS before switching to the other, the following two conditions are true in the Advanced tab of the Firefox Preferences menu:
    1) "Use autoscrolling" is enabled (with a check mark)
    2) "Always check to see if Firefox is the default browser on startup" is disabled (no check mark)
    The autoscrolling feature allows you to scroll by holding down the middle mouse button and moving the mouse up and down. The extension you linked to, ScrollyFox, enables scrolling by clicking a button in the Firefox UI, which is quite a different feature. So unfortunately the problems still remain.

  • Autoscrolling stopped working in Firefox 3.6.28 for Mac OS 10.4

    I have two Mac G4 desktop computers and have always had autoscrolling Firefox. Now the feature is no longer working. I don't recall updating Firefox recently, but can't go beyond my current version, 3.6.28 because the machines are not Intel.
    The autoscroll is very useful. I have tried checking the Preferences..Autoscrolling is checked. I have tried restarting. No luck. I cannot start in Safe Mode as there is no option for it.
    If there is some fix for this, it's not apparent on the Firefox Help Website.
    So any suggestion that would restore this feature will be very much appreciated. It doesn't seem to be a plug in, or and add on. My feeling is there may be some resetting procedure necessary...but I have no idea how to do that. Again, help to restore Autoscrolling very much appreciated. It worked for years...all I had to do was press the middle mouse button. It could go slow and faster. Now what happens when I press the middle button is that I get my dashboard apps. Hmm.
    Thanks!

    You need to use the command line switch -safe-mode in the Terminal to start Firefox 3.6 versions in Safe Mode.
    *https://support.mozilla.org/kb/Safe+Mode
    *http://kb.mozillazine.org/Safe_Mode
    The last Firefox version that runs on Mac OS X 10.4 is Firefox 3.6.28.
    For an unofficial Firefox 17.0.5 ESR compatible version (TenFourFox) that runs on PowerPC Macs with OS X 10.4.11 or OS X 10.5.8 you can look at:
    *http://www.floodgap.com/software/tenfourfox/
    *http://www.macupdate.com/app/mac/37761/tenfourfox
    *http://code.google.com/p/tenfourfox//wiki/ReleaseNotes1705
    *http://code.google.com/p/tenfourfox//wiki/PluginsNoLongerSupported
    *http://code.google.com/p/tenfourfox//wiki/QuickTimeEnabler
    *http://code.google.com/p/tenfourfox//wiki/AAATheFAQ

  • Need example of Autoscrolling in AS 3.0

    Can anyone point me to an AS 3.0 version of an "autoscroll"
    sample? You know, where there's a menu (like thumbnails) that
    automatically scroll left or right depending on where the mouse is?
    Move the mouse towards the left and the menu moves right and vice
    versa. when the mouse is dead center, the menu stops moving.
    I've done this before in AS 2.0 but can't seem to repeat it
    in AS 3.0.
    Thanks,
    Pat

    Phalcon, if you can e-mail me the AS2 version you have, I can
    look at it and update for AS3. [email protected]

  • Autoscroll with touchpad used to work in Firefox, but no longer does; works in other browsers and programs

    Just bought a new computer, enable autoscroll on the touchpad. It worked until a day or 2 ago (perhaps when I upgraded to Firefox 6???). I verified my setting in the touchpad control panel. I tested autoscroll in IE9 and it still works. Autoscroll using the scroll wheel on an external mouse in both Firefox and IE9.
    When using the touchpad autoscroll, the 'autoscroll" icon appears, but the page will not scroll (and it is long enough to do so).
    I also tried disabling add-ons to see if there was some conflict, but that did not resolve the issue either.
    Thanks,
    Marie

    Not sure but maybe something to do with casting. Below is the code snippet from one of the blogs. Try modifying your script like below and see if still you get the error
    [Microsoft.SharePoint.SPFieldUserValueCollection]$lotsofpeople = New-Object Microsoft.SharePoint.SPFieldUserValueCollection
    $user1 = $w.EnsureUser("domain\user1");
    $user1Value = New-Object Microsoft.SharePoint.SPFieldUserValue($w, $user1.Id, $user1.LoginName)
    $user2 = $w.EnsureUser("domain\user2");
    $user2Value = New-Object Microsoft.SharePoint.SPFieldUserValue($w, $user2.Id, $user2.LoginName);
    $lotsofpeople.Add($user1Value);
    $lotsofpeople.Add($user2Value);
    $i["lotsofpeoplefield"] = $lotsofpeople;
    $i.Update();
    #-or-
    $l.Fields["lotsofpeoplefield"].ParseAndSetValue($i,$lotsofpeople);
    $i.Update();
    Reference to the link
    http://social.technet.microsoft.com/wiki/contents/articles/20831.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-powershell.aspx
    Geetanjali Arora | My blogs |

  • How to set autoscroll function in docs delivered in PDF

    Hi
    I work regularly with PowerPoint slides which i sometimes deliver in PDF format to clients. And i would like to add the feature of autoscroll to the PDF itself so that when the user opens it the pages/slides start scrolling by themselves.
    Anybody know how its done?
    thanks
    Teri

    It should be 100 MOD 1000
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Autoscroll using Win7 default instead of Firefox override

    It appears that Firefox implements it's own version of autoscrolling on middle click on Windows 7. I say this because the icon does not look the same as in other Windows apps, and more importantly because of a specific behavior difference. In applications that use the generic Win7 autoscroll, moving the wheel up or down will cancel the autoscroll. Firefox doesn't do this; it moves a the page a little bit thanks to the scroll moving, but the autoscroll is still on. There does not appear to be a way to make Firefox just pass through the middle click to Windows, nor is there apparently a way to cancel on wheel movement. Is there any thing I can do to get this behavior? Thanks.

    Although not common, I am apparently not the only one who cards about this:
    https://support.mozilla.org/en-US/questions/802742?s=autoscroll&r=11&as=s
    I did not see that thread before I posted, although I am asking for something slightly deeper. I want an option to use the Windows default autoscroll / pan function rather than Firefox's override of it, which as a nice side benefit will give me the functionality of cancelling on scroll wheel movement.

  • Is there a way to save the Autoscroll as the default view in Acrobat X?

    I am trying to save autoscroll as the default view in acrobat.
    So when I open a new pdf it will automatically start scrolling.
    thanks

    The Acrobat forums are here:
    http://forums.adobe.com/community/acrobat
    This is the Reader one.

  • Datagrid Autoscroll Problem.

    Hi,
         I need one urgent help. I have a datagrid with lot of item renderers. While my datagrid has verticalscroll bar, i have one problem.
    while i click on an any row it autoscrolls itself to first row. I don't want it to autoscroll in this manner, because it affects my itemrenderer behaviour.
    Thanks,
    moorthi.

    Hi,
         Thanks to reply me.
         I am useing flex 3.5 Mx datagrid. i am using different item renderers in all columns. while i click on any row that will set as first row in datagrid.
    I am sure that is a defult behavior of Mx.Datagrid. Because i didn't do that in my code.
         If anyone faced this probelm, please reply.

  • Autoscrolling in a DropTarget (Drag and Drop)

    I have implemented Drag and Drop using DropTargets and a DragSource And DragGestureListener.
    The DropTarget I have is a customized JComponent. How can I make the DropTarget autoscroll for Drag and Drop events??

    Have you tried adding a MouseMotionListener to the target component and checking to see if the mouse coordinates are near the edge of the viewable area?

  • Autoscrolling in the DropTarget (Drag and Drop)

    I have implemented Drag and Drop using DropTargets and a DragSource And DragGestureListener.
    The DropTarget I have is a customized JComponent. How can I make the DropTarget autoscroll for Drag and Drop events??

    Have you tried adding a MouseMotionListener to the target component and checking to see if the mouse coordinates are near the edge of the viewable area?

  • Is there a way to autoscroll the timeline?

    Whenever the playhead reaches the right hand side of the timeline, the only way to keep it on screen is to manually drag the timeline to the left. I find this very annoying. Am I missing something here? Alternatively can I keep the playhead stationary and move the timeline under it?

    I use a logitech mouse with a mouse wheel that responds to "wheel tilt" left or right. When I bump the wheel, the timeline scrolls if the mouse cursor is over the timeline (even if FCPX is not the "active" application!) It's a little tricky with actual playback keeping the playhead in view, but you get a feel for it after awhile and I'm not trying to click-drag-follow.
    If you hold down the shift key and the right or left arrow keys, the timeline will autoscroll, but it's not actually playing, just skipping frames 10 at a time. It's a good way to "scan" through if you're looking for something specific.
    J,K, and L work pretty well too, if you're not all that concerned with focusing on the timeline. The playhead always comes back into view when Play, FF, or Rewind stop.

  • Making a JTable autoscroll

    I have a JTable with drag and drop functinality implemented. The problem is the user can only drag to a row that's visible on the screen. I know I have to implement the autoscroll interface in the java.awt.dnd package. How do you get the Insets for the JTable? Also how do you implement the autoscroll method? If there is another way to implement autoscrolling that would be helpful also.
    Thanks,
    William

    I guess the method you need is "scrollbarsWhenNeede" or sth. like that, can't remember the exact name.

  • Autoscroll behavior during DnD in JTree, 1.4 vs 1.6

    The following code compiles under both Java 1.4 and Java 1.6. I'm wondering if anyone knows why the following actions cause different behaviors between the two versions:
    1. When the frame opens, you should see a fully-expanded tree (which, because of the small size, causes a vertical scrollbar to appear).
    2. Make a drag-and-drop gesture on the first child node ("blue"), and attempt to cause the tree to scroll down so you can drop it on the last parent node ("food").
    Under 1.6, the tree scrolls nicely as you hold the DnD gesture.
    Under 1.4, the tree does not scroll. I had some hope JTree.setAutoscrolls(true) would help, but it did not.
    Any suggestions how to get 1.4 to behave the way 1.6 does?
    Thanks for your time.
    import javax.swing.*;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.TreeNode;
    import java.awt.*;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    import java.util.Enumeration;
    public class AutoScroll14 extends JFrame {
        public static void main(String[] args) {
            new AutoScroll14();
        public AutoScroll14() throws HeadlessException {
            super("AutoScroll 1.4");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            JTree tree = new JTree();
            tree.setDragEnabled(true);
            tree.setTransferHandler(new MyTransferHandler());
            expand(tree, tree.getPathForRow(0));
            JScrollPane sp = new JScrollPane(tree);
            sp.setPreferredSize(new Dimension(300, 200));
            Container content = getContentPane();
            content.setLayout(new BorderLayout());
            content.add(sp, BorderLayout.CENTER);
            pack();
            setVisible(true);
        private void expand(JTree tree, TreePath path) {
            TreeNode node = (TreeNode) path.getLastPathComponent();
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath newPath = path.pathByAddingChild(n);
                expand(tree, newPath);
            tree.expandPath(path);
        private class MyTransferHandler extends TransferHandler {
            private DataFlavor localStringFlavor;
            private String localStringType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.lang.String";
            private MyTransferHandler() {
                try {
                    localStringFlavor = new DataFlavor(localStringType);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
            public boolean importData(JComponent comp, Transferable t) {
                if (!canImport(comp, t.getTransferDataFlavors())) {
                    return false;
                String data = null;
                try {
                    if (hasLocalStringFlavor(t.getTransferDataFlavors())) {
                        data = (String) t.getTransferData(localStringFlavor);
                    } else {
                        return false;
                } catch (UnsupportedFlavorException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                String location = null;
                if (comp instanceof JTree) {
                    location = ((JTree) comp).getSelectionPath().toString();
                System.out.println("Dropping [" + data + "] on location [" + location + "]");
                return true;
            private boolean hasLocalStringFlavor(DataFlavor[] flavors) {
                if (localStringFlavor == null) {
                    return false;
                for (int i = 0; i < flavors.length; i++) {
                    if (flavors.equals(localStringFlavor)) {
    return true;
    return false;
    public boolean canImport(JComponent comp, DataFlavor[] flavors) {
    return hasLocalStringFlavor(flavors);
    protected Transferable createTransferable(JComponent c) {
    if (c instanceof JTree) {
    String toTransfer = ((JTree) c).getSelectionPath().toString();
    System.out.println("Creating transferable [" + toTransfer + "]");
    return new StringTransferable(toTransfer);
    System.out.println("Could not create transferable");
    return null;
    public int getSourceActions(JComponent c) {
    return COPY_OR_MOVE;
    private class StringTransferable implements Transferable {
    private String data;
    private StringTransferable(String data) {
    this.data = data;
    public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[] { localStringFlavor };
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    return localStringFlavor.equals(flavor);
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(flavor)) {
    throw new UnsupportedFlavorException(flavor);
    return data;

    I added the class "TreeDropTarget".
    "TreeDropTarget" extends the class "DropTarget", which implements the interface "DropTargetListener".
    DropTargetListener has a few methods, that are called automatically by Swing during drag operation
    (dragOver, dragExit, drop). So we can implement "autoscroll", as well as "automatic node expansion".
    With "automatic node expansion", a collapsed node will be expanded,
    so that its children become visible and we can do a drop on them:
    package demo;
    * AutoScroll.java
    * source level 1.4
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.dnd.*;
    import java.io.*;
    import java.util.*;
    public class AutoScroll extends JFrame {
        public static void main(String[] args) {
            new AutoScroll();
        public AutoScroll() throws HeadlessException {
            super("AutoScroll " + System.getProperty("java.version"));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            JTree tree = new JTree();
            tree.setDragEnabled(true);
            tree.setTransferHandler(new MyTransferHandler());
            tree.setDropTarget(new TreeDropTarget());//<----------------------
            expand(tree, tree.getPathForRow(0));
            JScrollPane sp = new JScrollPane(tree);
            sp.setPreferredSize(new Dimension(300, 200));
            Container content = getContentPane();
            content.setLayout(new BorderLayout());
            content.add(sp, BorderLayout.CENTER);
            pack();
            setVisible(true);
        private void expand(JTree tree, TreePath path) {
            TreeNode node = (TreeNode) path.getLastPathComponent();
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath newPath = path.pathByAddingChild(n);
                expand(tree, newPath);
            tree.expandPath(path);
        private class MyTransferHandler extends TransferHandler {
            private DataFlavor localStringFlavor;
            private String localStringType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.lang.String";
            private AutoScroll.MyTransferHandler.StringTransferable transferable;
            private MyTransferHandler() {
                try {
                    localStringFlavor = new DataFlavor(localStringType);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
            protected void exportDone(JComponent comp, Transferable t, int action) {
                if (t == null) {
                    t = transferable;
                if (!canImport(comp, t.getTransferDataFlavors())) {
                    return;
                String data = null;
                try {
                    if (hasLocalStringFlavor(t.getTransferDataFlavors())) {
                        data = (String) t.getTransferData(localStringFlavor);
                    } else {
                        return;
                } catch (UnsupportedFlavorException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                String location = null;
                if (comp instanceof JTree) {
                    location = ((JTree) comp).getSelectionPath().toString();
                System.out.println("Dropping [" + data + "] on location [" + location + "]");
                return;
            private boolean hasLocalStringFlavor(DataFlavor[] flavors) {
                if (localStringFlavor == null) {
                    return false;
                for (int i = 0; i < flavors.length; i++) {
                    if (flavors.equals(localStringFlavor)) {
    return true;
    return false;
    public boolean canImport(JComponent comp, DataFlavor[] flavors) {
    return hasLocalStringFlavor(flavors);
    protected Transferable createTransferable(JComponent c) {
    if (c instanceof JTree) {
    String toTransfer = ((JTree) c).getSelectionPath().toString();
    System.out.println("Creating transferable [" + toTransfer + "]");
    transferable = new StringTransferable(toTransfer);
    return transferable;
    System.out.println("Could not create transferable");
    return null;
    public int getSourceActions(JComponent c) {
    return COPY_OR_MOVE;
    private class StringTransferable implements Transferable {
    private String data;
    private StringTransferable(String data) {
    this.data = data;
    public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[]{localStringFlavor};
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    return localStringFlavor.equals(flavor);
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(flavor)) {
    throw new UnsupportedFlavorException(flavor);
    return data;
    class TreeDropTarget extends DropTarget {
    public TreeDropTarget() {
    super();
    public void dragOver(DropTargetDragEvent dtde) {
    JTree tree = (JTree) dtde.getDropTargetContext().getComponent();
    Point loc = dtde.getLocation();
    updateDragMark(tree, loc);
    autoscroll(tree, loc);
    super.dragOver(dtde);
    private Insets getAutoscrollInsets() {
    return autoscrollInsets;
    private void autoscroll(JTree tree, Point cursorLocation) {
    Insets insets = getAutoscrollInsets();
    Rectangle outer = tree.getVisibleRect();
    Rectangle inner = new Rectangle(
    outer.x + insets.left,
    outer.y + insets.top,
    outer.width - (insets.left + insets.right),
    outer.height - (insets.top + insets.bottom));
    if (!inner.contains(cursorLocation)) {
    Rectangle scrollRect = new Rectangle(
    cursorLocation.x - insets.left,
    cursorLocation.y - insets.top,
    insets.left + insets.right,
    insets.top + insets.bottom);
    tree.scrollRectToVisible(scrollRect);
    public void updateDragMark(JTree tree, Point location) {
    int row = tree.getRowForPath(tree.getClosestPathForLocation(location.x, location.y));
    TreePath path = tree.getPathForRow(row);
    if (path != null) {
    markNode(tree, location);
    private void markNode(JTree tree, Point location) {
    TreePath path = tree.getClosestPathForLocation(location.x, location.y);
    if (path != null) {
    if (lastRowBounds != null) {
    Graphics g = tree.getGraphics();
    g.setColor(Color.white);
    g.drawLine(lastRowBounds.x, lastRowBounds.y,
    lastRowBounds.x + lastRowBounds.width, lastRowBounds.y);
    tree.setSelectionPath(path);
    tree.expandPath(path);
    private Rectangle lastRowBounds;
    private Insets autoscrollInsets = new Insets(20, 20, 20, 20);

  • Change AutoScroll Bounds in JTextPane

    I cannot figure this out for the life of me. I would like to CHANGE the bounds for the autoscroll on a JTextPane that resides inside a JScrollPane when the user selects text and moves the mouse outside of the "autoscroll bounds".
    The normal bounds for scrolling down a JTextPane (when inside a JScrollPane) are usually the bounds of the JTextPane itself. (You can verify this with my example by selecting some text with the mouse button held down, and moving your cursor outside the bottom of the window). I would like to move the bottom bounds up higher into the window (indicated by the black line that resides on the glasspane).
    I have provided this example to use as a starting point. It doesn't do anything of use right now. I have tried about 20 things, but things have gotten so messed up, and the level of internal code that I started to mess around with got way over my head... so I'm just going to post this with a clean start, and hopefully we can move in a positive direction. I will relay my findings about a paticular route if we start moving down one i've already failed at.
    Thanks for you time.
    -Js
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.StyledDocument;
    public class AutoScrollTest extends JFrame
         //DATA
         private static final int Y_SCROLL_THRESHOLD = 150;
         //GUI
         private JPanel glassPanel;
         private JScrollPane scrollPane;
              private JTextPane textPane;
         public AutoScrollTest()
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setGlassPane(getGlassPanel());
              this.setContentPane(getScrollPane());
              getGlassPanel().setVisible(true);
              this.pack();
              this.setVisible(true);
         private JPanel getGlassPanel()
              if(glassPanel == null)
                   glassPanel = new JPanel()
                        public void paintComponent(Graphics g)
                             super.paintComponent(g);
                             g.setColor(Color.BLACK);
                             g.drawLine(0, Y_SCROLL_THRESHOLD, 300, Y_SCROLL_THRESHOLD);
                   glassPanel.setOpaque(false);
              return glassPanel;
         private JScrollPane getScrollPane()
              if(scrollPane == null)
                   scrollPane = new JScrollPane(getTextPane());
                   scrollPane.setPreferredSize(new Dimension(300,300));
              return scrollPane;
         private JTextPane getTextPane()
              if(textPane == null)
                   textPane = new JTextPane();
                   try
                        StyledDocument sd = textPane.getStyledDocument();
                        for(int i=1; i<1000; i++)
                             sd.insertString(sd.getLength(),"This is line: " + i + "\n", null);
                   catch(BadLocationException ble)
                        ble.printStackTrace();
              return textPane;
         public static void main(String args[])
              new AutoScrollTest();
    }

    camickr & StanislavL:
    Great work guys. I have used both of your ideas... and it works GREAT! I'll split the dukes between you.
    Please take a look at the finished code, its very cool. Again, thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class AutoScrollTest extends JFrame
         //DATA
         private static final int Y_SCROLL_THRESHOLD = 150;
         private Timer scrollTimer;
         //GUI
         private JPanel glassPanel;
         private JScrollPane scrollPane;
              private JTextPane textPane;
         public AutoScrollTest()
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setGlassPane(getGlassPanel());
              this.setContentPane(getScrollPane());
              getGlassPanel().setVisible(true);
              this.pack();
              this.setVisible(true);
         private JPanel getGlassPanel()
              if(glassPanel == null)
                   glassPanel = new JPanel()
                        public void paintComponent(Graphics g)
                             super.paintComponent(g);
                             g.setColor(Color.BLACK);
                             g.drawLine(0, Y_SCROLL_THRESHOLD, 300, Y_SCROLL_THRESHOLD);
                   glassPanel.setOpaque(false);
              return glassPanel;
         private JScrollPane getScrollPane()
              if(scrollPane == null)
                   scrollPane = new JScrollPane(getTextPane());
                   scrollPane.setPreferredSize(new Dimension(300,300));
              return scrollPane;
         private JTextPane getTextPane()
              if(textPane == null)
                   textPane = new JTextPane();
                   MouseInputAdapter mia = new MouseInputAdapter()
                        public void mouseDragged(MouseEvent e)
                             Point viewPortPoint = getScrollPane().getViewport().getViewPosition();
                             if(e.getY()-viewPortPoint.getY() > Y_SCROLL_THRESHOLD)
                                  getScrollTimer().start();
                             else
                                  getScrollTimer().stop();
                        public void mouseReleased(MouseEvent e)
                             getScrollTimer().stop();
                   textPane.addMouseListener(mia);
                   textPane.addMouseMotionListener(mia);
                   try
                        StyledDocument sd = textPane.getStyledDocument();
                        for(int i=1; i<1000; i++)
                             sd.insertString(sd.getLength(),"This is line: " + i + "\n", null);
                   catch(BadLocationException ble)
                        ble.printStackTrace();
              return textPane;
         private Timer getScrollTimer()
              if(scrollTimer == null)
                   scrollTimer = new Timer(60,new MyScrollListener(getTextPane(),getScrollPane().getVerticalScrollBar()));
              return scrollTimer;
         public static void main(String args[])
              new AutoScrollTest();
    class MyScrollListener implements ActionListener
         private JTextPane textPane;
         private JScrollBar scrollBar;
         public MyScrollListener(JTextPane textPane, JScrollBar scrollBar)
              this.scrollBar = scrollBar;
              this.textPane = textPane;
         public void actionPerformed(ActionEvent e)
              //Move down the scrollbar
              scrollBar.setValue(scrollBar.getValue()+scrollBar.getBlockIncrement());
              //Update the mouse highlight
              PointerInfo mousePointerInfo = MouseInfo.getPointerInfo();
              Point convertedPoint = SwingUtilities.convertPoint(null,mousePointerInfo.getLocation(),textPane);
              Position.Bias[] bias = new Position.Bias[1];
              int mouseOffset = textPane.getUI().viewToModel(textPane,convertedPoint, bias);
              if (bias[0] == Position.Bias.Backward && mouseOffset != 0)
                   --mouseOffset;
              textPane.setSelectionEnd(mouseOffset);
    }

Maybe you are looking for

  • I can't restore my system to its factory condition.

    hello all i have Pavilion DV6 laptop, my HardDisk is dmaged and i can't boot anymore (because of the physical BadSectors) , so ibought a new HardDisk ( 1TB ) when i plug my old hard disk into another PC , i can see the 3 partion's 1 : C:\[system] 2 :

  • Facetime....is it free when travelling out of the country?

    Is it like skype or are there charges for using it out of country?

  • Xorg 7 and KDE

    I followed this topic suggestions but I've got a problem running KDE. I configured KDM to autostart in init 5 mode and when I log into the system through it Arch doesn't login and takes me to KDM login again. If I log via console mode and I start xor

  • I need help with IOS 7, there is a major bug that needs to be fixed in an upcoming Update

    There is a big that needs to be FIXED an in upcoming update. Ok, on my ipad, the notifacation center says the weather is going to be 13 degrees celceuis, I am wanting to use the American metric units, which is Fahrenheit, how do I fix it, it says yah

  • Factory reset on HP Pavilion 17-f078no to windows 8.1

    I have a HP Pavilion 17-f078no with W8.1 pre installed. I installed windows 7 on it from a W7 DVD on c-drive (wiped the c-drive partition). I did not touch the other partitions. If I want to get back to W8.1 (as from factory), how do I get back to fa