You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX自定义ComboBox箭头无法显示红色背景问题求助

解决方案

问题核心在于你未给ComboBox的主控件容器设置红色背景——当前list-cell的样式仅作用于下拉列表的选项,箭头按钮所在的区域属于ComboBox的主控件部分,不受该样式影响。

调整CSS代码如下:

.custom-combobox .arrow-button {
    -fx-background-color: transparent;
    -fx-background-size: contain;
    -fx-background-repeat: no-repeat;
    -fx-background-position: center;
    -fx-background-image: url('../img/downArrow.png');
}

.custom-combobox .list-cell {
    -fx-pref-height: 70px;
    -fx-pref-width: 150px;
    -fx-background-color: red;
    -fx-background-size: 100% 100%; 
    -fx-background-position: center;
    -fx-alignment: center;
}

.custom-combobox .combo-box {
    -fx-max-height: 70px;
    -fx-max-width: 150px;
    -fx-background-color: red; /* 新增:设置ComboBox主背景为红色 */
    -fx-background-size: 100% 100%; 
    -fx-background-repeat: no-repeat;
    -fx-background-position: center;
    -fx-padding: 0; 
}

.custom-combobox .arrow {
    -fx-background-color: transparent;
    -fx-padding: 0;
    -fx-shape: null;
    /* 移除重复的背景图片设置,箭头已通过arrow-button显示 */
}

原理:ComboBox主容器设置红色背景后,箭头按钮因背景透明,会直接透出下方的红色,实现箭头后方显示红色的效果。

内容的提问来源于stack exchange,提问作者Simone Comignani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 15:14:56