Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6503981

Bug in BasicTableHeaderUI

XMLWordPrintable

    • b20
    • x86
    • windows_2000, windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.6.0-rc"
        Java(TM) SE Runtime Environment (build 1.6.0-rc-b99)
        Java HotSpot(TM) Client VM (build 1.6.0-rc-b99, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP
        Professional
        Version 2002
        Service Pack 2

        A DESCRIPTION OF THE PROBLEM :

        If you run the code below you will get a table, scroll right to the last table select column 39 and start moving it to the left. The column will jump straight to the beginning of the table instead of a normal move. The move triggers scrollRectToVisible which outputs:
        scroll to: left=0 right=75 visible: left=2511.0 right=3000.0
        scroll to: left=0 right=75 visible: left=0.0 right=489.0
        scroll to: left=0 right=75 visible: left=0.0 right=489.0
        scroll to: left=0 right=75 visible: left=0.0 right=489.0

        I think this bug is caused in BasicTableHeaderUI.mouseDragged(MouseEvent e)
        ....
        //Cache the selected column.
        int selectedIndex = table.convertColumnIndexToModel(getSelectedColumnIndex());

        //Now do the move.
        cm.moveColumn(columnIndex, newColumnIndex);

        //Update the selected index.
        selectColumn(table.convertColumnIndexToView(selectedIndex));
        return;
        ...

        selectedIndex is 0 and will be 0 after setting the new selected column. I think the call should be selectColumn(newColumnIndex), although the caching of the selectedIndex is probably done for a reason?

        Testcase:
        -- TestCase.java
        import java.awt.*;
        import javax.swing.*;
        import javax.swing.table.DefaultTableModel;
        public class TestCase extends JFrame {
            public TestCase() {
                super("test");
                setPreferredSize(new Dimension(500, 500));
                createContent();
            }
            public void createContent() {
             setLayout(new BorderLayout());
                JTable table = new JTable() {
                        @Override
                        public void scrollRectToVisible(Rectangle aRect) {
                            double leftVisible = getVisibleRect().getX();
                            double rightVisible = getVisibleRect().getX() + getVisibleRect().getWidth();
                            System.out.println("scroll to: left=" + aRect.x
                                               + " right=" + (aRect.x + aRect.width)
                                               + " visible: left=" + leftVisible
                                               + " right=" + rightVisible);
                            super.scrollRectToVisible(aRect);
            }
                    };
                table.setModel(new MyTableModel());
             table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                JScrollPane sp = new JScrollPane(table);
             this.add(BorderLayout.CENTER, sp);
            }
            public class MyTableModel extends DefaultTableModel {
                @Override
                public int getColumnCount() {
                    return 40;
                }
                @Override
                public String getColumnName(int column) {
                    return "column " + column;
                }
                @Override
                public int getRowCount() {
                    return 10;
        }
        @Override
                public Object getValueAt(int row, int column) {
                    return "" + row + ", " + column;
        }
            }
            /** @param args */
            public static void main(String[] args) {
                TestCase tc = new TestCase();
        tc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                tc.pack();
                tc.setVisible(true);
            }
        }
        --
        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        see above

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No "jumping" when scrolling
        ACTUAL -
        see above

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        None, I can't override relevant methods

        Release Regression From : 5.0u6
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

              idk Igor Kushnirskiy (Inactive)
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: