<Swing Dev> Review Request for Bug 8146320 JTextField ignores setPreferredSize when having columns
Prem Balakrishnan
prem.balakrishnan at oracle.com
Thu Jan 21 05:52:05 UTC 2016
Hi Sergey, Alexander
Updated Webrev: documentation updated respectively
http://cr.openjdk.java.net/~rchamyal/prem/8146320/webrev.01/
Regarding JTextArea:
The behavior of setting preferred size and columns/rows are similar to JTextField.
i.e., If Columns and rows are set, the values are used to calculate the area size.
If setPreferredSize() is called explicitly, then the size is modified respectively,
overriding the size set by columns/rows, But when getPreferredSize() is called,
it still returns the size multiplied by colum/row.
Hence check similar to JTextField is required in case of JTextArea.
Should I update changes to JTextArea ????
Regards,
Prem
-----Original Message-----
From: Sergey Bylokhov
Sent: Thursday, January 21, 2016 6:56 AM
To: Prem Balakrishnan; Alexander Scherbatiy; Ambarish Rapte; Rajeev Chamyal; swing-dev at openjdk.java.net
Subject: Re: Review Request for Bug 8146320 JTextField ignores setPreferredSize when having columns
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