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

Alexey Ivanov aivanov at openjdk.org
Mon Nov 6 19:37:32 UTC 2023


On Mon, 6 Nov 2023 06:22:33 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:
> 
>   Reinstate setEnabled

Actually, I meant [the opposite thing](https://github.com/openjdk/jdk/pull/15325#pullrequestreview-1594282373): override `setMinimumSize` and `setMaximumSize` *to specify* the behaviour that `JScrollBar` currently has, which is specified by its `getMinimumSize` and `getMaximumSize`.

I ran an app which creates three scrollbars:
* The first one doesn't modify its size;
* The second one sets its min and max size;
* The third one sets its preferred size in addition to min and max.

The resizing behaviour differs between the current implementation and the PR.

Previously, the secondary axis was fixed, when the frame is resized the secondary axis isn't resized, the scroll bar remains at its preferred size. If the preferred size was set, the size along the secondary axis again becomes fixed. If the frame is to a smaller size, the scrollbar gets clipped. If the frame grows larger than the preferred size, the size of the scrollbars is increased.

I guess the idea was to make scrollbar *always* at its preferred size along its secondary axis. But `setPreferredSize` doesn't enforce it.

With the `getMinimumSize` and `getMaximumSize` removed, as in the current state in this PR, the scrollbar becomes flexible along its secondary axis too. Thus, the third scrollbar, which has all three sizes set, accommodates the changes in size: it grows or shrinks as the frame is resized. The second scrollbar starts growing only after the the third one reaches its minimum size; after the second scrollbar reaches its maximum size, the third scrollbar gets clipped.

I'm inclined to keep the current behaviour of `getMinimumSize` and `getMaximumSize` as it gives the most pleasing look to the scrollbar. At this time, it could be too late to modify `setPreferredSize` so that it modifies only the value along its main axis, yet this would give the best appearance in my opinion. Is there any application which uses scrollbars not at its preferred size along the secondary axis?

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

PR Comment: https://git.openjdk.org/jdk/pull/15325#issuecomment-1796167220


More information about the client-libs-dev mailing list