RFR: 6510914: JScrollBar.getMinimumSize() breaks the contract of JComponent.setMinimumSize() [v11]

Alexey Ivanov aivanov at openjdk.org
Wed Jan 24 14:44:38 UTC 2024


On Tue, 23 Jan 2024 03:37:45 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> javadoc contract for JComponent.setMinimumSize(Dimension) states:
>> 
>> "Sets the minimum size of this component to a constant value. Subsequent calls to getMinimumSize will always return this value..."
>> 
>> However, JScrollBar overrides getMinimumSize() and breaks this contract - it always returns a minimum size derived from the preferred size even if you have previously called setMinimumSize()
>> 
>> Fix is made to check if mnimumSize is set and if so, honour it..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   PR update as per review

Changes requested by aivanov (Reviewer).

src/java.desktop/share/classes/javax/swing/JScrollBar.java line 761:

> 759:      * Thus, it overrides {@code JComponent.setMinimumSize} contract
> 760:      * that subsequent calls to getMinimumSize will return the
> 761:      * same value as set in {@code JComponent.setMinimumSize}

Suggestion:

     * Unlike most components, {@code JScrollBar} derives the minimum size from
     * the preferred size in one axis and a fixed minimum size in the other.
     * Thus, it overrides {@code JComponent.setMinimumSize} contract
     * that subsequent calls to {@code getMinimumSize} will return the
     * same value as set in {@code JComponent.setMinimumSize}.


@prrace Should the first sentence use the present tense instead of the future?

There should be a period in the end of the sentence.

Should we add a paragraph saying, calling `setMinimumSize` has no effect?

src/java.desktop/share/classes/javax/swing/JScrollBar.java line 789:

> 787:      * fixed minimum size in the other.
> 788:      *
> 789:      * @return the minimum size as specified above.

The first sentence of the javadoc is put into the method summary, therefore the first sentence should explain what is returned. Is it worth addressing it too?

Something like: Returns the minimum size for the {@code JScrollBar}. The minimum size is equal to a fixed minimum value along its scrolling axis and the preferred size along the other axis.

src/java.desktop/share/classes/javax/swing/JScrollBar.java line 807:

> 805:      * fixed maximum size in the other.
> 806:      *
> 807:      * @return the maximum size as specified above.

This can be amended in a similar way to `getMinimumSize`.

Returns the maximum size for the {@code JScrollBar}. The maximum size is equal to a fixed maximum value its scrolling axis and the preferred size along the other axis. This makes the scrollbar flexible along its scrolling axis and rigid along the other axis.

-------------

PR Review: https://git.openjdk.org/jdk/pull/15325#pullrequestreview-1841501224
PR Review Comment: https://git.openjdk.org/jdk/pull/15325#discussion_r1464989992
PR Review Comment: https://git.openjdk.org/jdk/pull/15325#discussion_r1465006089
PR Review Comment: https://git.openjdk.org/jdk/pull/15325#discussion_r1465014788


More information about the client-libs-dev mailing list