如何更改JComboBox弹出部分的边框? [英] How do you change border of the pop up section of a JComboBox?

查看:414
本文介绍了如何更改JComboBox弹出部分的边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wan't to change the border of the popup/selection part of the JComboBox.

注意UI是BasicComboBoxUI

Note that the UI is BasicComboBoxUI

我试过:

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

但它给了我这个:

but it gave me this:

和:

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

但它给了我这个:

我想要的是这样的: (它是在photoshop中完成的)
我不介意它是不是完全没有同样,我只是不相似。

what i wan't is something like this: (it was done in photoshop) I don't mind if it's not exactly the same, I just wan't it similar.

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

does anyone have any ideas on how to do this?

推荐答案

这样的工作原理:

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

这篇关于如何更改JComboBox弹出部分的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆