Bug: ComboBox dropdown list of combobox is not taking Scale Transformation in consideration

M Fox martin at martinfox.com
Tue Mar 8 18:42:30 UTC 2022


Out of curiosity I decided to take a look at this bug. I’m a Java and JavaFX newbie so take this all with a massive grain of salt.

It’s not at all clear how to take the control's cumulative transform and create a transform to apply to the popup. Even isolating the scale is tricky if a rotation was applied somewhere along the Node chain. If JavaFX tried to do this itself I suspect defining the behavior would be way more difficult than implementing it.

It’s possible for a client to do this directly for some controls including ComboBoxes. Create a subclass of the ComboBox skin (the base class would be ComboBoxListViewSkin) and override it’s getPopupContent() method to retrieve the Node from super and apply whatever transforms you want. Then create a subclass of ComboBox and override it’s createDefaultSkin() method to return an instance of your custom skin.

This approach also works for ColorPickers and DatePickers. I couldn’t see any way of applying it to ChoiceBoxes, internally they use ContextMenus and don’t expose them in any way. I think that would be an easy problem to solve. MenuBars are too deep for me.

public class CustomComboBoxSkin<T> extends ComboBoxListViewSkin<T> {
    public CustomComboBoxSkin(ComboBox<T> comboBox) {
        super(comboBox);
    }

    @Override
    public Node getPopupContent() {
        Node result = super.getPopupContent();
        result.getTransforms().setAll(new Scale(0.5, 0.5, 0.0, 0.0));
        return result;
   }
}

public class CustomComboBox<T> extends ComboBox<T> {
    @Override
    protected Skin<?> createDefaultSkin() {
        return new CustomComboBoxSkin<>(this);
    }
}

> On Mar 7, 2022, at 8:20 AM, Kevin Rushforth <kevin.rushforth at oracle.com> wrote:
> 
> This sounds like JDK-8088757 [1], "Scale of control does not cross to popup in popup-based controls". Yes, it does seems like a legitimate bug to me. Fixing it might result in a surprising behavior change for some existing applications, given how long this behavior has been in place (the bug in question was filed 10 years ago), but that's not a good enough reason to avoid fixing the bug. As usual, it will come down to priorities. If someone has time to fix this, it will make it a lot more likely for it to be fixed.
> 
> -- Kevin
> 
> [1] https://bugs.openjdk.java.net/browse/JDK-8088757
> 
> On 3/6/2022 4:52 PM, Neacsu Cristian wrote:
>> Hello,
>> 
>> I am using ComboBoxes all over the place in my application.
>> Until now, my application was in full-screen mode. Now due to the request
>> of clients to create the possibility to move it around on multiple screen,
>> I created the option to move it on dual screens and so on. To achieve
>> different resolution I am using the Scale transformation and add it to the
>> main node, in order to scale everything.
>> Everything is working properly, but the drop down list is taking the width
>> of the combo box unscaled (and if resolution differs from the one that was
>> initiated, the drop down list width will differ from the combobox itself).
>> Is it a legit bug?
>> 
>> Thank you in advance,
>> Cristian-Stefan
> 




More information about the openjfx-dev mailing list