scijava / scijava-ui-swing

SciJava UI components for Java Swing.
BSD 2-Clause "Simplified" License
7 stars 11 forks source link

Spinners are missing up/down arrows with FlatLaf #77

Closed ctrueden closed 1 year ago

ctrueden commented 1 year ago

As reported on the Image.sc Forum:

Unfortunately, spinner buttons in ImageJ2 style ContextCommand plugins are missing. Other L&Fs work.

To reproduce:

imagesc-bot commented 1 year ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/missing-spinner-buttons-with-flatlaf-look-and-feel/72185/2

DevCharly commented 1 year ago

Following lines cause the problem:

https://github.com/scijava/scijava-ui-swing/blob/40bd474d8b9b169d521a621ddf9772a718ce6e26/src/main/java/org/scijava/ui/swing/widget/SwingNumberWidget.java#L131-L133

spinner.getSize() always returns 0, 0 because the spinner was just created and is not yet layouted. So the preferred height of the spinner becomes 0, which FlatLaf does not like. Probably a bug in FlatLaf. Will investigate...

Anyway seems that the intention of the above code is to limit the preferred width of the spinner. Replacing spinner.getSize() with spinner.getPreferredSize() should fix the issue.

imagejan commented 1 year ago

Thanks for the suggestion, @DevCharly. I can confirm this fixes the issue, and opened #78.

tferr commented 1 year ago

FYI, I actually don't think (I could be, of course, wrong - I did not test any other L&F) limiting the preferred width of the spinner is needed. Things seem to work fine if one leaves it to defaults. Maybe this is just some historic code that has been carried over!? On #79, I have a couple of proposals on things that I found when looking into this.

tferr commented 1 year ago

FYI, I actually don't think (I could be, of course, wrong - I did not test any other L&F) limiting the preferred width of the spinner is needed. Things seem to work fine if one leaves it to defaults

I was wrong of course. The rationale for this is explained here: https://github.com/scijava/scijava-ui-swing/pull/79#issuecomment-1264787285