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

JTable: rowAtPoint returns 0 for negative y

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 5.0
    • client-libs
    • Fix Understood
    • x86
    • windows_2000

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      doesn't matter

      A DESCRIPTION OF THE PROBLEM :

      synopsis says it all: table.rowAtPoint(new Point(<negativevalue>, somevalue) returns 0 instead of -1. This happens for

      -1 >= <negativeValue> > -table.getRowHeight()

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run unittest


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * $Id: JXTreeTable.java,v 1.4 2005/05/31 11:14:41 kleopatra Exp $
       *
       * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
       * Santa Clara, California 95054, U.S.A. All rights reserved.
       */

      import java.awt.Point;

      import javax.swing.JTable;

      import junit.framework.TestCase;

      /**
       * @author Jeanette Winzenburg, Berlin
       */
      public class JTableIssues extends TestCase {

          public void testTableRowAtNegativePoint() {
              JTable treeTable = new JTable(1, 4);
              int negativeYRowHeight = - treeTable.getRowHeight();
              int negativeYRowHeightPlusOne = negativeYRowHeight + 1;
              int negativeYMinimal = -1;
              // just outside of negative row before first row
              assertEquals("negative y location rowheight " + negativeYRowHeight + " must return row -1",
                      -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));
              // just inside of negative row before first row
              assertEquals("negative y location " + negativeYRowHeightPlusOne +" must return row -1",
                      -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));
              // just outside of first row
              assertEquals("minimal negative y location must return row -1",
                      -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));
              
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :

      subclass JTable (done in JXTable of SwingLabs SwingX):

          /**
           * workaround bug in JTable (negative y is mapped to row 0).
           */
          public int rowAtPoint(Point point) {
              if (point.y < 0) return -1;
              return super.rowAtPoint(point);
          }
      ###@###.### 2005-06-28 13:31:36 GMT

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: