<Swing Dev> Editable combobox vs LaF change: javax.swing.plaf.UIResource vs javax.swing.plaf.basic.BasicComboBoxEditor.UIResource

Vladimir Sitnikov sitnikov.vladimir at gmail.com
Fri Mar 20 12:06:01 UTC 2020


Hi,

I'm facing an issue that the editor for an editable combo box resets its
border as LaF changes.
It results in "textfield with border inside combobox" which looks weird.

Here are the screenshots of how it looks:
https://github.com/weisJ/darklaf/issues/104

While I analyzing the issue, I found an interesting code in the OpenJDK.

https://github.com/openjdk/jdk/blob/6dffcf753301385a5eeb869276967234126e509c/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java#L155

    static class BorderlessTextField extends JTextField {
...
        public void setBorder(Border b) {
            if (!(b instanceof UIResource)) {
                super.setBorder(b);
            }
        }

Even though it looks OK, it is using **wrong** UIResource.
I think the author was supposed to use javax.swing.plaf.UIResource,
however, in practice the code is comparing the instance of
javax.swing.plaf.basic.BasicComboBoxEditor.UIResource
which is a simple class defined at the end of the file:

    public static class UIResource extends BasicComboBoxEditor
    implements javax.swing.plaf.UIResource {
    }

I think BorderlessTextField#setBorder should be updated to read if (!(b
instanceof javax.swing.plaf.UIResource)).

Any thoughts on that?

Vladimir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/swing-dev/attachments/20200320/de9600fb/attachment.htm>


More information about the swing-dev mailing list