<Swing Dev> Review Request for Bug 8146320 JTextField ignores setPreferredSize when having columns

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Thu Feb 25 10:43:17 UTC 2016


Hi, Prem.
It seems that I was not clear in my previous email. Small clarification:
Usually we can fix/change an existed code in a few situations:
1 Behavior is changed if it contradicts the specification.
2 The specification is changed if it contradicts the long-term behavior
3 If some behavior is unspecified and can varies from platform to 
platform(usually we clarify the spec and align implementation).

In your fix you change the spec and behavior. So initially, some time 
ago, someone wrote this specification and implemented behavior of 
JTextField according to this specification. So applications depend from 
this behaviour(which is properly specified) and we simply cannot change 
it now.

On 21.01.16 8:52, Prem Balakrishnan wrote:
> Hi, Prem.
> This change actually contradicts to the specification of JTextField.
>
> Check the specification:
>       /**
>        * Constructs a new <code>JTextField</code> that uses the given text
>        * storage model and the given number of columns.
>        * @param columns  the number of columns to use to calculate
>        *   the preferred width >= 0; if <code>columns</code>
>        *   is set to zero, the preferred width will be whatever
>        *   naturally results from the component implementation
>        */
>       public JTextField(Document doc, String text, int columns) {
>
>       /**
>        * Returns the preferred size <code>Dimensions</code> needed for this
>        * <code>TextField</code>.  If a non-zero number of columns has been
>        * set, the width is set to the columns multiplied by
>        * the column width.
>        *
>        * @return the dimension of this textfield
>        */
>       public Dimension getPreferredSize() {
>
> Note that this class explicitly states in two places that if the columns are set then they will be used for calculation of the preferred size. So such change will require a javadoc update.
>
> PS: I wonder why the same functionality in JTextArea is specified and implemented differently....
>
>
>
> On 18/01/16 13:46, Prem Balakrishnan wrote:
>> Hi,
>>
>> Please review fix for JDK9,
>>
>> *Bug:*https://bugs.openjdk.java.net/browse/JDK-8146320
>>
>> *Webrev:*http://cr.openjdk.java.net/~rchamyal/prem/8146320/webrev.00/
>>
>> *Issue:*
>>
>> JTextField ignores setPreferredSize when having columns
>>
>> *Cause:*
>>
>> JTextField setPreferredSize is not actually ignored , when column value
>> is set>0.
>>
>> While retrieving the values set using getPreferredSize(), wrong values
>> were returned.
>>
>> *Fix:*
>>
>> Check added, if Column>0 and if Preferred size is not set after setting
>> columns, while retrieving values.
>>
>> Regards,
>> Prem
>>
>
>


-- 
Best regards, Sergey.



More information about the swing-dev mailing list