JavaFX:隐藏ComBox箭头

时间:2016-12-28 09:56:58

标签: javafx combobox

我正在尝试使用here中的方法隐藏ComboBox箭头,但由于某种原因,我得到了这个: enter image description here

2 个答案:

答案 0 :(得分:0)

试试这个:

.combo-box, .arrow, .arrow-button{
    -fx-background-color: transparent;
}

去掉所有出现的其他颜色(聚焦:border-color / border-glow和unfocused:shadow)add .text-field

.combo-box, .arrow, .arrow-button, .text-field{
    -fx-background-color: transparent;
}

请注意,每个文字字段/箭头/箭头按钮都会受到影响。要解决这个问题,您需要将css样式表添加到节点本身

your-combo-box-node.getStylesheets().add(Main.class.getResource("styles.css").toExternalForm());

如果您需要更灵活地设置节点本身各个部分的样式,请拆分css-code-line

.combo-box{ -fx- ... }
.arrow{ -fx- ... }
.arrow-button{ -fx- ... }
.text-field{ -fx- ... } 

答案 1 :(得分:0)

这确实是旧文章,但如果有人需要,则只是更新。如果只想设置一个组合框的样式,则可以用另外两种方法进行设置。首先在Css中定义组合的ID

#idOfTheComboBox>  .arrow-button > .arrow {
   -fx-background-color: transparent;
}
#idOfTheComboBox>  .arrow-button {
   -fx-background-color: transparent;
}

或与班级

.your-class >  .arrow-button > .arrow {
   -fx-background-color: transparent;
}
.your-class >  .arrow-button {
   -fx-background-color: transparent;
}