<Swing Dev> [9] Review Request for 8001470: JTextField's size is computed incorrectly when it contains Indic or Thai characters

Semyon Sadetsky semyon.sadetsky at oracle.com
Mon Apr 27 15:12:36 UTC 2015


Hello,

Please review JDK9 fix.
webrev: http://cr.openjdk.java.net/~ssadetsky/8001470/webrev.00/
bug: https://bugs.openjdk.java.net/browse/JDK-8001470


***ROOT CAUSE
The setVisible() call without pack() or setBounds() means set the frame 
size to the initial window size. The initial window size usually is the 
size to fit the window frame and title only, so the content pane 
receives some width and zero height. Since GridLayout does not limit 
minimum component size when doing layout under fixed size, the 
components receive zero height. This situation we have right after the 
setVisible(true) call.
Now we do call our pack() call to do layout of the fame which is already 
visible. The pack() triggers getPreferedSize() calls for components. 
Calculation of TextFileld preferred size is performed in its View which 
setSize() method should be called. For an i18n text filed the view is a 
complex data structure which requires the right initialization. 
According to line 942 of the BasicTextUI class the view initialization 
happens only when both component's width and height equal to 0, which is 
an expected situation for the initial layout call. But in our specific 
pack() call this never happens because while the height is actually 
equals 0 the width is not, because component received such size as the 
result of the previous frame.setVisible() call. So the view.setSize() 
method is not called at all and preferred size is calculated 
incorrectly, the zero height is obtained particularly.

***SOLUTION
As a fix it is proposed to change condition in line 942 of the 
BasicTextUI to OR to cover the scenario.

***TESTING
A test case for the scenario is added.

--Semyon



More information about the swing-dev mailing list