How to set border for combo box?

Answered

import com.intellij.openapi.ui.ComboBox;
ComboBox cmbList = new ComboBox();

As you can see the combo boxes has no borders in dracula theme. I set the border explicitly for the combo box but blue color hover effect that provided by intelliJ IDE isn't working. How to set border that supports intelliJ hovereffect as well?

0
6 comments

We do no recommend changing the default appearance of builtin Swing controls. Why do you need to change it?

0

IntelliJ[2020.1] Combobox has built in border style but with our implementation the border is not visible for darcula theme. Actually we are trying to mimic this same appearance to our combo box.

0
Avatar
Permanently deleted user

Why don't you use standard implementation?

Desired behavior is provided by com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI, not just border.

0
ComboBox cmbList = new ComboBox();
cmbList.setUI(new DarculaComboBoxUI());

I already tried with this darcula UI but the result is same. The combobox not contains the border even after set darcula combobox UI

The same implementation is working with 2017 intellIJ IDE. 2019 intelliJ and the upper versions not support the border.

IntelliJ Idea version 2017 combobox

0
Avatar
Permanently deleted user

You shouldn't set UI by your own as it works automatically by design. When you change theme custom border would be reset together with whole component UI. Border customization is not recommended for comboboxes but still you can do a trick:

ComboBox cmbList = new ComboBox() {
@Override
public void updateUI() {
super.updateUI();
setBorder(...);
}
};
0

Thank you for your support and guidance. I fixed this combo box UI issue as you said.

0

Please sign in to leave a comment.