如何将 TextArea 绑定到 String 以创建终端
How to bind a TextArea to a String to create a Terminal
我的目标是创建一个终端。为此,我使用 TextArea
,我收到 数据 ,我将其放入 StringProperty
,然后我想 绑定此 StringProperty
到我的 TextArea
.
我是这样做的 :
在收到数据的class中:
StringProperty sendData = new SimpleStringProperty();
WHEN I RECEIVE DATA : sendData.set(Arrays.toString(strings));
在 class 中 包含 TextArea :
@FXML private TextArea consoleTextArea = new TextArea();
public void setLiaison (StringProperty textRecu){
consoleTextArea.textProperty().bind(textRecu);
}
在第三个 class 中,我初始化所有内容,然后调用 setLiaison(sendData);
但这行不通:
- 修改 StringProperty 后,我的 TextArea 中没有显示任何内容。
- 即使显示出来了,我也希望
StringProperty
的下一个变化写在第一行下方的TextArea中,而不是抹掉再写,怎么办?
谢谢。
编辑:完整控制器Class:
public class ConsoleViewController implements Initializable{
@FXML private VBox consoleVBox;
@FXML private HBox titleHBox;
@FXML private Label consoleLabel;
@FXML private Button closeButton;
@FXML private TextArea consoleTextArea;
public void setLiaison (StringProperty textRecu){
consoleTextArea.textProperty().bind(
Bindings.concat(consoleTextArea.getText()).concat("\n").concat(textRecu.get()));
}
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
}
}
I have nothing that displays in my TextArea when the StringProperty is modified.
您不应该使用 new
关键字初始化控件引用,该关键字已用 @FXML
注释。这些字段在加载 FXML 时初始化。只需使用 :
@FXML
private TextArea consoleTextArea;
I would want the next change on the StringProperty to be written in the TextArea below the first line, not erase it and write again.
您可以使用以下方法将追加文本设置到 TextArea:
consoleTextArea.appendText(textRecu.getText()+"\n");
我的目标是创建一个终端。为此,我使用 TextArea
,我收到 数据 ,我将其放入 StringProperty
,然后我想 绑定此 StringProperty
到我的 TextArea
.
我是这样做的 :
在收到数据的class中:
StringProperty sendData = new SimpleStringProperty();
WHEN I RECEIVE DATA : sendData.set(Arrays.toString(strings));
在 class 中 包含 TextArea :
@FXML private TextArea consoleTextArea = new TextArea();
public void setLiaison (StringProperty textRecu){
consoleTextArea.textProperty().bind(textRecu);
}
在第三个 class 中,我初始化所有内容,然后调用 setLiaison(sendData);
但这行不通:
- 修改 StringProperty 后,我的 TextArea 中没有显示任何内容。
- 即使显示出来了,我也希望
StringProperty
的下一个变化写在第一行下方的TextArea中,而不是抹掉再写,怎么办?
谢谢。
编辑:完整控制器Class:
public class ConsoleViewController implements Initializable{
@FXML private VBox consoleVBox;
@FXML private HBox titleHBox;
@FXML private Label consoleLabel;
@FXML private Button closeButton;
@FXML private TextArea consoleTextArea;
public void setLiaison (StringProperty textRecu){
consoleTextArea.textProperty().bind(
Bindings.concat(consoleTextArea.getText()).concat("\n").concat(textRecu.get()));
}
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
}
}
I have nothing that displays in my TextArea when the StringProperty is modified.
您不应该使用 new
关键字初始化控件引用,该关键字已用 @FXML
注释。这些字段在加载 FXML 时初始化。只需使用 :
@FXML
private TextArea consoleTextArea;
I would want the next change on the StringProperty to be written in the TextArea below the first line, not erase it and write again.
您可以使用以下方法将追加文本设置到 TextArea:
consoleTextArea.appendText(textRecu.getText()+"\n");