我用TextField
加上叉号来清除输入。当我这样添加它时:
public class Controller implements Initializable {
@FXML
private TextField autoCompleteTextField = TextFields.createClearableTextField();
...
然后:
@Override
public void initialize(URL location, ResourceBundle resources){
autoComplete1 = TextFields.bindAutoCompletion(autoCompleteTextField,callback, converter);
autoCompletePane.getChildren().add(autoCompleteTextField);
一切正常。但是当我想在SceneBuilder中添加该项目或在Fxml中手动添加该项目时:
<Pane fx:id="autoCompletePane" prefHeight="30.0" prefWidth="444.0">
<children>
<CustomTextField fx:id="autoCompleteTextField" layoutX="25.0" layoutY="3.0" />
// or TextField instead of CustomTextField
</children>
</Pane>
插入常规TextField
,不带叉号以清除输入。
我该怎么办?
答案 0 :(得分:0)
您可以指定一种static
方法,该方法不使用参数来使用the fx:factory
attribute创建文本字段:
<Pane fx:id="autoCompletePane" prefHeight="30.0" prefWidth="444.0">
<children>
<TextFields fx:id="autoCompleteTextField" fx:factory="createClearableTextField" layoutX="25.0" layoutY="3.0" />
</children>
</Pane>
(这当然需要针对TextFields
类的导入处理指令。)