想要一些帮助来使用javafx在textarea中获取文本的气泡聊天,所以我尝试添加其他方法,例如左语音气泡和右语音气泡,但是那行不通。所以我想把文本放在气泡内。
private void initComponents(VBox root) {
incoming = new TextArea();
double height = 500;
double width = 300;
incoming.setPrefHeight(height);
incoming.setPrefWidth(width);
incoming.setFont(Font.font ("Verdana", 15));
incoming.setEditable(false);
incoming.setFocusTraversable(false);
incoming.setBorder((new Border(
new BorderStroke(Color.AQUA, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT))));
incoming.setStyle(
"-fx-focus-color: -fx-control-inner-background ; -fx-faint-focus-color: -fx-control-inner-background ; -fx-background-image: url(file:Airbus.jpg)");
root.getChildren().add(incoming);
outgoing = new TextField();
outgoing.setFont(Font.font ("Verdana", 15));
root.getChildren().add(outgoing);
root.setAlignment(Pos.CENTER);
send = new Button("SEND");
send.setOnAction(e -> {
String text = outgoing.getText();
if (text.length() > 0) {
incoming.appendText(userName + ": " + text + "\n");
outgoing.selectAll();
writer.println(outgoing.getText());
writer.flush();
}
outgoing.requestFocus();
outgoing.clear();
});
outgoing.setOnKeyPressed(ke -> {
if (ke.getCode() == KeyCode.ENTER) {
send.fire();
}
});
send.setPrefSize(WIDTH, 30);
root.getChildren().add(send);
userName = WindowUtils.buildTextDialog("What is your name?", "Please enter your name :", "Name");
//greet user:
incoming.appendText("AirBot" + ": Your name " + userName + "? I'm taking notes now...\n");
}