个性化JComboBox Java

问题描述

我想自定义JComboBox,所以我将模型与ListCellRenderer一起使用,我的目标是通过将对象悬停为橙色来更改项目的背景,然后得到它。

结果示例:

Example of how it turned out

但是我稍微改变了组合框的样式,它看起来有点金属质感,我怎么能使它看起来像原始的,传递指针时的背景颜色不是蓝色而是橙色,颜色代码我使用的是 [255,142,0]

原件示例:

Example of the original

这里显示了用于自定义组合框的代码

public class PropertyCombo extends BasicComboBoxUI {

    Color c = new Color(255,0);

    public static ComboBoxUI createUI(JComponent com) {
        return new PropertyCombo();
    }

    @Override
    protected ListCellRenderer createRenderer() {
        return new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList<?> jlist,Object o,int i,boolean bln,boolean bln1) {
                super.getListCellRendererComponent(jlist,o,i,bln,bln1); 

                jlist.setSelectionBackground(c);

                return this;
            }
        };
    }
}

并将此自定义添加到JComboBox代码为:

cbx_name.setUI(PropertyCombo.createUI(this));

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)