Insubstantial / insubstantial

Swing look-and-feel library and assorted widgets
193 stars 58 forks source link

Problem about JRE8 upgrade with JXTable cannot high light entire one row #133

Closed andylan closed 10 years ago

andylan commented 10 years ago

I found that JRE8(64bit) with JXTable cannot high light entire one row, like below(which is OK for JRE6(64bit) and JRE7(64bit))

I found the problem was caused class SubstanceTableUI. TableCellId method hashCode, like below: jre8

public int hashCode() { //noinspection ShiftOutOfRange return (this.row ^ (this.row >>> 32)) & (this.column ^ (this.column >>> 32)); }

Which is ok for JRE6 and JRE7, but have problem with JRE8,

I used below code to do test,

public class ShiftOutOfRangeHashCode { public static void main(String[] args) { List tableCellIdLst = new ArrayList(100); Multiset tableCellSet = HashMultiset.create(); int row = 5; int column = 5; TableCellId tableCellId; for (int i = 0 ; i < row; i++) { for (int j = 0; j < column; j++) { tableCellId = new TableCellId(i,j); tableCellIdLst.add(tableCellId); tableCellSet.add(tableCellId); } }

    for (TableCellId tempTableCellId : tableCellIdLst) {
        int frequency = tableCellSet.count(tempTableCellId);
        System.out.println(tempTableCellId + " frequency=" + frequency);
    }
}

}

With JDK7(64bit) test as below: "C:\Program Files\Java\jdk1.7.0_51\bin\java" Row 0, Column 0 frequency=1 Row 0, Column 1 frequency=1 Row 0, Column 2 frequency=1 Row 0, Column 3 frequency=1 Row 0, Column 4 frequency=1 Row 1, Column 0 frequency=1 Row 1, Column 1 frequency=1 Row 1, Column 2 frequency=1 Row 1, Column 3 frequency=1 Row 1, Column 4 frequency=1 Row 2, Column 0 frequency=1 Row 2, Column 1 frequency=1 Row 2, Column 2 frequency=1 Row 2, Column 3 frequency=1 Row 2, Column 4 frequency=1 Row 3, Column 0 frequency=1 Row 3, Column 1 frequency=1 Row 3, Column 2 frequency=1 Row 3, Column 3 frequency=1 Row 3, Column 4 frequency=1 Row 4, Column 0 frequency=1 Row 4, Column 1 frequency=1 Row 4, Column 2 frequency=1 Row 4, Column 3 frequency=1 Row 4, Column 4 frequency=1

But with JDK8(64bit) test as below: "C:\Program Files\Java\jdk1.8.0_05\bin\java" Row 0, Column 0 frequency=0 Row 0, Column 1 frequency=0 Row 0, Column 2 frequency=0 Row 0, Column 3 frequency=0 Row 0, Column 4 frequency=0 Row 1, Column 0 frequency=0 Row 1, Column 1 frequency=0 Row 1, Column 2 frequency=1 Row 1, Column 3 frequency=0 Row 1, Column 4 frequency=0 Row 2, Column 0 frequency=0 Row 2, Column 1 frequency=1 Row 2, Column 2 frequency=0 Row 2, Column 3 frequency=0 Row 2, Column 4 frequency=0 Row 3, Column 0 frequency=1 Row 3, Column 1 frequency=0 Row 3, Column 2 frequency=0 Row 3, Column 3 frequency=0 Row 3, Column 4 frequency=1 Row 4, Column 0 frequency=0 Row 4, Column 1 frequency=1 Row 4, Column 2 frequency=0 Row 4, Column 3 frequency=1 Row 4, Column 4 frequency=1

Here with JDK8(64bit), for some record cannot find, but which just added before.

For the problem, I can modify class SubstanceTableUI. TableCellId method hashCode, like below, and then JXTable would display OK.

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#equals(java.lang.Object)
     */
   @Override
    public boolean equals(Object o) {
      /*  if (obj instanceof TableCellId) {
            return this.compareTo((TableCellId) obj) == 0;
        }
        return false;*/
        boolean equals = false;
        if (o != null &&
                TableCellId.class.isAssignableFrom(o.getClass()) ) {
            TableCellId other = (TableCellId)o;
            equals = (new EqualsBuilder()
                    .append(this.row, other.getRow())
                    .append(this.column, other.getColumn())
            ).isEquals();
        }
        return equals;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        //noinspection ShiftOutOfRange
      /*  return (this.row ^ (this.row >>> 32))
                & (this.column ^ (this.column >>> 32));*/
        return new HashCodeBuilder(INITIAL_PRIME, PRIME)
                .append(this.row).append(this.column).toHashCode();
    }

Class detail please refer to https://github.com/Insubstantial/insubstantial/blob/master/substance/src/main/java/org/pushingpixels/substance/internal/ui/SubstanceTableUI.java

There is another class SubstanceMonthViewUI have the same problem

andylan commented 10 years ago

The issue is same with another issue FIX #130 Chaotic mouse rollover painting on JTable (java8) #131 , detail please refer to https://github.com/Insubstantial/insubstantial/pull/131, and solution please refer to https://github.com/Insubstantial/insubstantial/pull/131/files