如何更改JComboBox弹出部分的边框?

时间:2012-02-17 04:27:35

标签: java swing border jcombobox jlist

我不想改变JComboBox的弹出/选择部分的边框。

请注意,UI是BasicComboBoxUI

我试过了:

weaponCB.setRenderer(new DefaultListCellRenderer() {
        @Override
        public void paint(Graphics g) {
       setBorder(whiteBorder)
//whiteBorder is a white border             
       super.paint(g);
        }
    });

但它给了我这个: enter image description here

    for (int i=0; i<weaponCB.getComponentCount(); i++)
    {
        if (weaponCB.getComponent(i) instanceof AbstractButton)
        {
            ((AbstractButton)weaponCB.getComponent(i)).setBorder(whiteBorder);
        }
    }

但它给了我这个:enter image description here

我不想是这样的:(它是在photoshop中完成的) enter image description here我不介意它是不是完全相同,我只是不相似。

有没有人对如何做到这一点有任何想法?

1 个答案:

答案 0 :(得分:2)

这样的工作:

Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
BasicComboPopup popup = (BasicComboPopup)child;
JList list = popup.getList();
list.setBorder( whiteBorder );