Scroll JTable in Scrollpane with mouse drag

Hello developers !
I'm trying to make a scrollable Jtable. The table have to be scrollable with the mouse drag event. But I have a "flashing" Problem. I can catch the Mouse events from the table (I'm listener the mouse motion and mouse events).
When I receive a new mouse drag event, I set the new position from the viewport. The problem is, that the Table flash:
For example:
I drag the mouse to the bottom of the table. The mouse "y" position have to increase, but it doesn't:
first motion event position (10, 10)
second motion event position (10, 15)
third motion event position (10, 12)
etc..
The position of the mouse event are in relation of the component position. I think, the problem is that I change the position of the view port and than the new mouse event is "on a wrong reference".
Could someone help me? How could I make a work around for this Problem?

I have the solution... it is easy.
I post the solution because i spent two days making working around (changing viewport position other scrollbar values, etc).
You dont need to implement the Autoscroll interface. The Autoscroll interface is for Drag and Drop classes.
The key was the function JTable#scrollRectToVisible....
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class ScrollableTableFrame extends JFrame{
  protected ScrollableTable table;
  public ScrollableTableFrame() {
    super("Scrollable Table");
    setSize(600, 300);
    String data[][] = new String[40][40];
    String header[] = new String[40];
    for(int i = 0; i < 40; i++){
      header[i] = "Header " + i;
      for(int j = 0; j < 40; j++){
        data[i][j] = "(" + i + ", " + j +")";
    ScrollableTable table = new ScrollableTable(data, header);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JScrollPane sp = new JScrollPane();
    sp.getViewport().setBackground(table.getBackground());
    sp.getViewport().add(table);
    getContentPane().add(sp, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);
    setVisible(true);
  public static void main(String args[]){
    new ScrollableTableFrame();
class ScrollableTable extends JTable{
  private Point firstPressedPoint;
  public ScrollableTable(Object rowData[][], Object columnNames[]){
    super(rowData, columnNames);
  protected void processMouseEvent(MouseEvent e){
    int id = e.getID();
    switch(id) {
      case MouseEvent.MOUSE_PRESSED:
        firstPressedPoint = e.getPoint();
        break;
      case MouseEvent.MOUSE_RELEASED:
        firstPressedPoint = null;
        break;
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_ENTERED:
    super.processMouseEvent(e);
  protected void processMouseMotionEvent(MouseEvent e){
    if(e.getID() == MouseEvent.MOUSE_DRAGGED){
      Rectangle r = getVisibleRect();
      Point p = e.getPoint();
      int dx = (firstPressedPoint.x-p.x);
      int dy = (firstPressedPoint.y-p.y);
      Rectangle aRect = new Rectangle(r.x + dx, r.y + dy , r.width + dx, r.height + dy);
      scrollRectToVisible(aRect);
}P.S.: jarshe, thank you for your help !!

Similar Messages

  • RowHeader scrolling with mouse drag

    I have created a JTable in a scrollpane that has
    both column headers and row headers.
    If I drag the mouse in the table vertically, when
    I get to the edge the table and row headers will
    scroll automatically.
    However, if I drag the mouse vertically in the row
    headers, the headers start to scroll, but the table
    does not.
    My row headers are implemented as a JList and are
    added to the rowHeaderView of the JScrollPane.
    Do I need to add a drag listener to my JList
    and do something special to sync these up?
    Thanks for any help.
    -Mark

    Call setAutoscrolls(false) in the constructor of your header renderer.

  • How to remove a black border box that continously tabs to each field automatically till end of web page; restarts to top of page, cannot stop this box. Scroll bar cannot controlled with mouse, returns auto to top of scroll slide, never remaining at bottom

    how to remove a black border box that continously tabs to each field automatically till end of web page; restarts to top of page, cannot stop this box. Scroll bar cannot be controlled with mouse, scroll bar returns automatically to the top of scroll slide every time I move the bar to the bottom of the scale.  Also, there's a rectangular text box (with black background and white text) that is always on the desktop that emulates a typed text, HTML, or cmd function.

    cjuan1morb4ulv wrote:
    how to remove a black border box that continously tabs to each field automatically till end of web page; restarts to top of page, cannot stop this box. Scroll bar cannot be controlled with mouse, scroll bar returns automatically to the top of scroll slide every time I move the bar to the bottom of the scale.  Also, there's a rectangular text box (with black background and white text) that is always on the desktop that emulates a typed text, HTML, or cmd function.
    The first two problems (box cycling from element to element on page, scroll bar returning to top) can be caused by a stuck (or defective) Tab key on the keyboard. Such damage can be caused by a liquid spill; just one tiny droplet is enough to short a wafer switch under one key.
    The last issue (black box, white text - sounds sorta like a debugger window) I haven't seen, but could be caused by something similar.
    To check for that, try using a different keyboard. If you're using a wireless keyboard, turn it off and see if the oddities stop.

  • Scrolling of grid records with mouse scroll

    Hi,
    Is it possible to scroll iGrid records using scrollable mouse?
    Your comments are appreciated.
    Best Regards,
    Kedar

    Kedar,
    take a look at the following thread with the same question:
    [http://forums.sdn.sap.com/click.jspa?searchID=47087653&messageID=8453941]
    Maybe you are lucky in MII 12.1. Previous versions cannot scroll with the mouse in iGrids.
    Michael

  • JTable custom selection and mouse drag events

    Hello
    I am currently experiencing a problem when using a JTable and a custom selection. I have made a small example to demonstrate the probem. Selection works for this example by listening for when the user clicks or clicks and drags (button held down) and moves the mouse across cells in the table. For each MouseEvent received in the MouseMotionListener mouseDragged method I store the coordinates of that cell at the point of the mouse and render the cell at those coordinates with a line border allowing a more versatile cell selection. The problem that occurs is when you click+drag and move the mouse fast, it looks MouseEvents are created every x milliseconds so when you move fast there isn't a MouseEvent raised for each cell in the click+drag from A -> B. If you run the following example then click and hold down the mouse button and move fast downwards from the top of the table to the bottom you can see that not all the cells are selected vertically.
    Is there someway of increasing the mouse poll (if this is indeed the problem) during the click+drag or a better solution to this problem that any one knows!?
    I have tried attaching the example but it exceeded the message length for the forum post here is a link to code
    [http://www.oneandonlyluppy.pwp.blueyonder.co.uk/TableTest.java]
    [http://www.oneandonlyluppy.pwp.blueyonder.co.uk/TableTest.zip] <-- Contains the source and compiled classes
    I'll try adding the code again as a separate post
    Thanks
    Edited by: oneandonlyluppy on Jan 8, 2009 2:44 AM
    Edited by: oneandonlyluppy on Jan 8, 2009 2:45 AM

    AFAIK the mouse polling rate is OS dependent (being interrupt driven), and may even be affected by processor load. What you could do is store the mouse location (Point) of the last mouseDragged event, and compute a line to the current location, then use some coordinate geometry to identify any intervening cells which are presently being skipped.
    db

  • Mouse Dragging slow on X Terminal (SunRay)

    Hi,
    We're getting some curious behaviour with mouse drag events when running our java client app on an X Terminal (a SunRay 1 in this case).
    It seems that events are not delivered to the client while the drag is in progress but only after the user stops moving the mouse for about a second. Needless to say, this is very annoying and kinda kills the interactivity in our app.
    This delay seems to get worse the faster you move the mouse.
    It's not just our app, either. All java apps we've tried do the same thing.
    The delay gets smaller if you go all the way back to JVM 1.2, but all newer versions have the problem.
    Sooooooo, what I'd like to know is:
    - is this a known problem with SunRays?
    - is there any configuration option in Java or the X Server I can tweak to improve performance?
    TIA,
    Andrew

    I don't know the answer, but perhaps these links will help:
    http://developer.java.sun.com/developer/bugParade/bugs/4669873.html
    http://developer.java.sun.com/developer/bugParade/bugs/4485987.html
    I hope this sheds at least a bit of light on your problem,
    regards,
    Alex

  • Tabcontrol transitions between tab with mouse gesture ?

    Hi
    Can we create a tabcontrol with gridview in tab, and when we can scroll gridview and tabcontrol with mouse hold and move ?
    Example :
    Tab1 Tab2
    1 2   5 6
    3 4 7 8
    When we hold and move mouse Up-Down gridview will scroll in tab.
    When we hold and move mouse Left-Right we will see tab transtion
    Tab1 Tab2
    .. 2 5 ..
    .. 4 6 ..
    Tab navigation will dependent where we release mouse.
    Exactly i want do something the same app screen smart phone, exclude it can scroll in Up-Down in a page.
    I'm researching in Google but now see anything sample like this.
    Please help me.
    Sorry for my bad english.

    Hi Cygnus
    Durant
    I'm not really what you said.
    We will create 
    <TabPanel >
    <ScrollViewer>
    <StackPanel >
    <Item>
    So will
    horizontal smooth-scroll we will use ScrollViewer
    Add handlers for MouseMove to
    scroll verically in StackPanel ?
    Sorry i'm just beginner.

  • Scroll with mouse scroller - possible?

    hello!
    i'm in desperate need!! for this website i'm helping in, the
    client wanted me to scroll this section with words AND images. so ,
    i used the scroll pane component from Flash mx8. it works. but, now
    the client wants it to scroll faster when using their mouse
    scroller.
    currently it does scroll, but very slowly. is there another
    tutorial i could scroll both text and images with the mouse
    scroller? i'm still using action script 2.0

    Its Very simple select your ScrollPane and increase the
    vLineScrollSize / hLineScrollSize property

  • Scrolling with mouse on pages create black and white lines,

    When scrolling with mouse, periodically the whole screen turns into black and white lines. Sometimes whole page, sometimes just pictures/side ads. If you continue to scroll it does go away but then you need to scroll back to where the lines started, its hard to explain, i have taken 1 photo of the problem but will take more photos as i can, i really enjoy how Firefox runs on my computer, it has always been the best browser for my needs. I did recently buy a new desktop, but it did it then also, so i removed it and tried running explorer and Google and i just don't like them, so i am hoping we can get this fixed.

    Try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    *https://hacks.mozilla.org/2010/09/hardware-acceleration/
    If there is a problem with scrolling on web pages then try to disable smooth scrolling.
    *Tools > Options > Advanced > General: Browsing: "Use smooth scrolling"

  • My laptop touchpad scroll is not working with firefox 4. It is wroking with other programs. When I attach a mouse then scroll works with mouse wheel. It is only not working with touchpad. It is/was working with firefox 3.6.x

    I am using windows xp service pack 3 with Lenovo T60p.

    I too have this problem, I have an Acer Aspire 7551G with an ALPS mutitouch touchpad. It works perfectly fine in every other program, and worked in Firefox 3.6. Scroll also works fine with a USB mouse. I tried downloading the 'latest' driver from the Acer support website, but when I tried to install it, it says that I am trying to install the same driver that I already have, so that fix isn't possible. I've only had the machine for 3 months, so I would imagine the drivers are pretty current.
    I can't believe that this is a driver problem anyway, as I say, it works perfectly well in every other program, so it must be something wrong with Firefox. I was looking forward to using Firefox 4, but this problem is too annoying to put up with. Oh well, back to Chrome... at least until there is a fix found or implemented.

  • Cant scroll horizontally with mouse wheel in FF

    I cant scroll horizontally in FF unter XP+SP3 by pressing the mouse wheel sideways. This is the same in FF 3.6 and 4.0 beta, while in IE 6.0 and in other MS programs (Explorer, Word, ...) it works fine. I am having this problem with 2 different mice: Fujitsu 400NB and easytouch ET-9600. I cant find newer drivers for them than what I have installed from the CDs. Here some settings from my FF: mousewheel.horizscroll.withnokey.action;0 mousewheel.horizscroll.withnokey.numlines;1 mousewheel.horizscroll.withnokey.sysnumlines;true. Some time ago I played around with them but that didn't help. What else can I do to get FF scrolling horizontally?

    This should get you there
    http://css-tricks.com/snippets/jquery/horz-scroll-with-mouse-wheel/
    1. Load the mousewheel min script via CDN (jquery-mousewheel - cdnjs.com - the missing cdn for javascript and css)  into the Scripts Panel;
    2. Add the provided snippet into your Stage > compositionReady event handler.
    hth
    Darrell

  • Create an image scroller with swipe&drag in Edge Animate

    Hi folks!
    I'm trying to create a image scroller like this one http://www.awwwards.com/demo/touchSwipe-gallery-demo.html.
    For the Swipe, I use the wonderful JQuery Plugin TouchSwipe http://labs.rampinteractive.co.uk/touchSwipe/demos/, but for the image sliding I would use the Adobe Edge Animate Timeline.
    I know that I can use the Swipe events in Edge Animate to make start or reverse the timeline with pictures, but I would also make working an intermediate "dragging".
    My problem, in fact, is: how can I make that - if I've only begun to swipe  and I move the finger to left or right without releasing it - my timeline "drag" (or scrubs) frame by frame - like in the example above - until I release the finger?
    Many thanks in advance!
    Davide

    Hi Elaine!
    First, thanks for your prompt answer!
    I read the link you gave me: in fact, I was aware - also thanks to Old Tim's posts - about how to create a "scrubber" in Edge Animate, starting from formulas like:
    Translation = (positionOfScrubber/WidthOfScrubbing)*timeline;
    My problem now is - I fear - more subtle: I can swipe left-right a set of pictures, I can "scrub" a timeline (using for example JqueryUI for the dragging), but I don't know how to put together the swiping and the dragging.
    I would that - like in the example from my first post - if, e.g., I completed the swipe left, my timeline would play the animation that shows the pic moving to the left but, if I didn't complete the swiping and I begun dragging to the left, the animation would move with my dragging-finger (the "scrubbing")...
    I know is very subtle, but it's how the gallery scrollers works on web and app in mobile devices...
    Many thanks for your attention!
    Davide

  • Have transferred from old computer to macbook air and have lost ability to scroll with mouse has gone to scroll bar. Can I fix this

    Have transferred data from my old computer to new MacBook Air. New computer now uses scroll bar like older version. Can I return the MacBook Air to scrolling with mouse pad.

    Open Mouse or Trackpad preferences in System Preferences and be sure the scroll setting is correct.

  • Horizontal scrolling with mouse wheel?

    I have built a website for a client that scrolls only horizontally. Is it possible to scroll with the mouse wheel horizontally?
    Is there certain HTML I need to add?
    Thank you

    Hi,
    There is no out of the box solution to force horizontal scrolling with mouse wheel. However, you can add your own code to your Muse site after exporting it. These docs should be helpful :
    http://css-tricks.com/snippets/jquery/horz-scroll-with-mouse-wheel/
    http://stackoverflow.com/questions/2346958/how-to-do-a-horizontal-scroll-on-mouse-wheel-sc roll
    Regards,
    Aish

  • Why am I unable to scroll through bookmarks with mouse wheel anymore?

    Used to be able to scroll through bookmarks with mouse wheel, now I am unable to. I have tried reinstalling firefox and disabling all addons but same problem. Please help!

    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.

Maybe you are looking for

  • Need Matrix Style Report...

    I need to create a matrix style report. There is a template for matrix reports in Oracle Report Writer, but not in APEX. My report should have a list of countries going down and a list of species going across with data showing how many for each count

  • How to Trace ABAP Webdynpro Application?

    Dear Friends, We are trying analyse performance bottle neck for ABAP Webdynro application. We have an Webdynpro Application named Z_APPLICTION_URL in NW 7.0 SP16 which is calling 4 RFC's in R/3 4.7 to fech data. Users lauch this application using URL

  • How to change sorting behavior in column view in Lion Finder?

    I love the ability to sort in column view in OS X 10.7. However, when I switch to column view and let sort by label, the Finder displays a strange behavior: The files are grouped by label, but in the order of lee to more. It does not seem possible to

  • Update Fail  U44M1P7 ??

    I tried downloading the new updates today and I get th error U44M1P7 update fail. Now my Photoshop won't open either  , How do I fix this ??  windows 7 64 bit thanks

  • VMware server Console -- not the web based access

    Dear All,         I want to install vmware server console to do Oracle RAC practice, So kindly let me know from where can I get the exe file to install it.        FYI , I installed Vmware server version2.0.2 but it's ( Web access infrastructure )  ,