JDK-8158209 : Editing in TableView breaks the layout, when the document is I18n
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2016-05-27
  • Updated: 2017-03-29
  • Resolved: 2017-03-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b161Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+119)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+119, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux Mageia 5.

A DESCRIPTION OF THE PROBLEM :
1- Beware, the display (with java 9 119) for I18nLayoutTest.java is not the same with i18n true (bad display) and with i18n false (good display). With i18n true, the table go down.

JDK 9 b119 corrects JDK-8133864 bug, but it introduices a bad display of the table which go down.

( I18nLayoutTest.java is a test program of the OpenJDK.
It's the same program I sent for the previous Bugs JDK-7169915 and JDK-8133864 ).

2- Please, please ... could someone examine again the patch for JDK-7169915 that I suggested 4 years ago ? I really need it to implement table, matrix, ... display in my application. I've spent long time in 2012 to find what was wrong in tableview. I know Victor's comment was not good but you could compare with the tableview implementation in the swing/text/html package which works fine.

REGRESSION.  Last worked in version 8u92

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Put the document I18n property false :
putProperty("i18n", Boolean.FALSE);
the display is right (a text with a  table) when we insert text.

Put the document I18n property true :
putProperty("i18n", Boolean.TRUE);
the table goes down when we insert text.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The table stays in the same line when we insert text, like i18n false.
ACTUAL -
 When i18n true, the table goes down when we insert text.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
( I18nLayoutTest.java is a test program of the OpenJDK.
It's the same program I sent for the previous Bugs JDK-7169915 and JDK-8133864 ).
---------- END SOURCE ----------


Comments
I am finding that this is not an issue. The layout of TableView is correct. The table cells got a height according to their text content and the cell view allocation equals to text size. In the provided CodeBug.java the bug reporter draws a table frame using the cell allocation rectangle but if in some cells text has smaller height than in other cells the table frame looks bad.To draw the correct frame it's better to use the table row height or let the cell to adjust its height to the row height: @Override public View create(Element elem) { String kind = elem.getName(); if (kind != null) { if (kind.equals(CodeBugDocument.ELEMENT_TR)) { return new trView(elem); } else if (kind.equals(CodeBugDocument.ELEMENT_TD)) { return new BoxView(elem, View.Y_AXIS) { @Override public float getMaximumSpan(int axis) { if(axis == Y_AXIS) { return Integer.MAX_VALUE; // <------------ cell may fill full row height } return super.getMaximumSpan(axis); } }; } } As for the horizontal frame lines, the trView class shouldn't override getMaximumSpan(int axis) or at least does not limit its width to the preferred span width. Hope these recommendations will help to the bug reporter.
08-09-2016

fix is proposed on the Swing alias by guy.abossolo.foh@scientificware.com. It was created for JDK8 and integrates the JDK-8133864 fix which is not backported to 8 yet. diff --git a/src/share/classes/javax/swing/text/CompositeView.java b/src/share/classes/javax/swing/text/CompositeView.java --- a/src/share/classes/javax/swing/text/CompositeView.java +++ b/src/share/classes/javax/swing/text/CompositeView.java @@ -24,7 +24,7 @@ */ package javax.swing.text; -import java.util.Vector; +import java.util.*; import java.awt.*; import javax.swing.event.*; import javax.swing.SwingConstants; @@ -182,9 +182,14 @@ views = ZERO; } + Set<View> set = new HashSet<>(Arrays.asList(views)); // update parent reference on removed views for (int i = offset; i < offset + length; i++) { - if (children[i].getParent() == this) { + View child = children[i]; + if (child.getParent() == this && !set.contains(child)) { + // update parent reference on removed views + //for (int i = offset; i < offset + length; i++) { + // if (children[i].getParent() == this) { // in FlowView.java view might be referenced // from two super-views as a child. see logicalView children[i].setParent(null); diff --git a/src/share/classes/javax/swing/text/TableView.java b/src/share/classes/javax/swing/text/TableView.java --- a/src/share/classes/javax/swing/text/TableView.java +++ b/src/share/classes/javax/swing/text/TableView.java @@ -78,6 +78,8 @@ super(elem, View.Y_AXIS); rows = new Vector<TableRow>(); gridValid = false; + // Bug 1 (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + totalColumnRequirements = new SizeRequirements(); } /** @@ -345,6 +347,14 @@ // continue normal layout super.layoutMinorAxis(targetSpan, axis, offsets, spans); } + + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + @Override + public void preferenceChanged(View child, boolean width, boolean height) { + // Instead of clean columnRequirements in calculateColumnRequirements we could use invalidateGrid() + //invalidateGrid(); + super.preferenceChanged(child, width, height); + } /** * Calculate the requirements for the minor axis. This is called by @@ -377,6 +387,11 @@ r.preferred = (int) pref; r.maximum = (int) max; r.alignment = 0; + + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + totalColumnRequirements.minimum = r.minimum; + totalColumnRequirements.preferred = r.preferred; + totalColumnRequirements.maximum = r.maximum; return r; } @@ -406,6 +421,15 @@ * into consideration any constraining maximums. */ void calculateColumnRequirements(int axis) { + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + // (see preferenceChanged for another solution) + // clean columnRequirements + for (SizeRequirements req : columnRequirements) { + req.minimum = 0; + req.preferred = 0; + req.maximum = Integer.MAX_VALUE; + } + // pass 1 - single column cells boolean hasMultiColumn = false; int nrows = getRowCount(); @@ -576,10 +600,13 @@ int[] columnSpans; int[] columnOffsets; + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + SizeRequirements totalColumnRequirements; + SizeRequirements[] columnRequirements; Vector<TableRow> rows; boolean gridValid; - static final private BitSet EMPTY = new BitSet(); + private static final BitSet EMPTY = new BitSet(); /** * View of a row in a row-centric table. @@ -645,6 +672,56 @@ super.replace(offset, length, views); invalidateGrid(); } + + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + // The major axis requirements for a row are dictated by the column + // requirements. These methods use the value calculated by + // TableView. + protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) { + SizeRequirements req = new SizeRequirements(); + req.minimum = totalColumnRequirements.minimum; + req.maximum = totalColumnRequirements.maximum; + req.preferred = totalColumnRequirements.preferred; + req.alignment = 0f; + return req; + } + + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + public float getMinimumSpan(int axis) { + float value; + + if (axis == View.X_AXIS) { + value = totalColumnRequirements.minimum + getLeftInset() + getRightInset(); + } else { + value = super.getMinimumSpan(axis); + } + return value; + } + + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + public float getMaximumSpan(int axis) { + float value; + + if (axis == View.X_AXIS) { + // We're flexible. + value = (float) Integer.MAX_VALUE; + } else { + value = super.getMaximumSpan(axis); + } + return value; + } + + // Bug (JDK-7072926 : Swing Table Layout Update) & (JDK-7169915 : Swing Table Layout bad repaint of the row) + public float getPreferredSpan(int axis) { + float value; + + if (axis == View.X_AXIS) { + value = totalColumnRequirements.preferred + getLeftInset() + getRightInset(); + } else { + value = super.getPreferredSpan(axis); + } + return value; + } /** * Perform layout for the major axis of the box (i.e. the
08-09-2016

Not a regression because JDK-8133864 reports only a display issue and says nothing about editing. JDK-8133864 fixed the display issue, but then i18n document layout was broken by JDK-8143177 fix which is fixed now by JDK-8158924. So, editing issue in i18n document with TableView is firstly reported by the current issue.
08-09-2016

Checked this for 8u92 b31, 9 ea b119 and 9 ea b120 on Ubuntu (Linux) and could confirm the issue as reported by the submitter. Steps to Reproduce: Run the attached test case (CodeBug.java) with the JDK version. Test Result: ######### OS: Ubuntu Linux 64 bit, Windows 7 64 bit JDK: Regression : ================ 8u92 b31 : Pass (i18n=false) 8u92 b31 : Pass (i18n=true) --------------> But not getting the complete table while executing Affect's Version: ============== 9ea+119 : Pass (i18n=false) 9ea+119 : Fail (i18n=true) Latest ea Version: ============= 9ea+120 : Pass (i18n=false) 9ea+120 : Fail (i18n=true) ============================================================================================== It looks like an issue to me. Therefore, moving this issue over JDK for dev team's evaluation.
31-05-2016