[英]ScalaFX/JavaFX: How can I change the overrun style of a ComboBox?
我需要设置所选项目的溢出样式 。 据我所知,要设置溢出样式,我需要访问buttonCell
(类型为ObjectProperty[javafx.scene.control.ListCell[T]]
)。
因此我写了
val fileComboBox = new ComboBox[java.io.File](Seq())
println(fileComboBox.buttonCell)
为了查看buttonCell
成员具有哪个值。
结果: [SFX]ObjectProperty [bean: ComboBox@319f91f9[styleClass=combo-box-base combo-box], name: buttonCell, value: null]
,这意味着没有可以设置其溢出样式的按钮单元格( value: null
)。
如何更改组合框的溢出样式?
您可以使用外部CSS文件执行此操作:
.combo-box > .list-cell {
-fx-text-overrun: leading-ellipsis ;
}
有效值为[ center-ellipsis | center-word-ellipsis | clip | ellipsis | leading-ellipsis | leading-word-ellipsis | word-ellipsis ]
[ center-ellipsis | center-word-ellipsis | clip | ellipsis | leading-ellipsis | leading-word-ellipsis | word-ellipsis ]
[ center-ellipsis | center-word-ellipsis | clip | ellipsis | leading-ellipsis | leading-word-ellipsis | word-ellipsis ]
其中ellipsis
为默认值。
您也可以通过直接设置按钮单元格来执行此操作。 在JavaFX中(我将让您将其翻译为Scala):
ListCell<File> buttonCell = new ListCell<File>() {
@Override
protected void updateItem(File item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? null : item.getName());
}
};
buttonCell.setTextOverrun(OverrunStyle.LEADING_ELLIPSIS);
fileComboBox.setButtonCell(buttonCell);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.