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

Phil Race prr at openjdk.org
Fri Nov 17 19:00:36 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

I'm not seeing anything I'd call truly bad here.
But I do have another suggestion that actually might have been the best thing to do all those years ago.
Keep the over-ride as the default behaviour, and document it better.
But if the app calls setMaximumSize or setMinimumSize() then honour it like you are supposed to.
 I suspect very few apps actually call these since they are complete no-ops today.
If we do that, then yes, you'll still see differences if you do call those APIs and forgot about it because it didn't make a difference.

If that isn't going to work, then, I think we should fall back to the pure documentation solution.
Well, almost pure docs, but not quite, because we need a no-op over-ride of set* on which to place the docs.

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

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


More information about the client-libs-dev mailing list