Unable to move column to end of table when horizontal scroll bar is active
I have a table with 40 columns, but only about 30 of them are visible at the same time due to the restricted screen width. When I move the scroll bars to the right-most position and try to drag a column, lets say from position 38 to 36, the scroll bars immediately jumps to the left-most position an I can only move the column to position 30 or lower.
As a result, I'm not able to rearrange all columns that are not visible when the scroll bars is on its left-most position :-(
[491 byte] By [
karsten76a] at [2007-11-27 10:57:16]

# 1
It sort of works for me. I have the opposite problem. The scrollbar doesn't move as you are dragging to the left so you can't see where you are dragging the column to:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=623692
# 2
I have nearly the same setup as described in your code snippet:
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
setRowSelectionAllowed(true);
setColumnSelectionAllowed(false);
Perhaps the differences occurs because of the Java version? I'm currently using 6u1 ...
# 4
I tried the code in the mentioned example and the same problem occurs - the scroll bar immediately jumps to the start of the table ...
So neither the old nor the new behaviour allows you to move columns freely :-(
# 6
Check out the JComponent.setAutoscrolls(...) method. I modified the example code from the API and added the following to my above example:
MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
JViewport vp = scrollPane.getViewport();
Point p = vp.getViewPosition();
p.x = e.getX();
Rectangle r = new Rectangle(e.getX(), p.y, 1, 1);
table.scrollRectToVisible(r);
}
};
table.getTableHeader().addMouseMotionListener(doScrollRectToVisible);
Automatic scrolling now occurs when dragging a column.
Don't know if it will help in JDK6 or not.
Message was edited by:
camickr