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.

Reply via email to