I have a problem, where, when trying to readjust the screen, the text that is inside a TextFlow
, goes out of the screen, and is not set down.
public SwingFXPanel(ServicosJson json) {
this.json = json;
this.cliente = cliente;
this.msgs = new ArrayList<>();
this.chatBox = new VBox();
this.scroll = new ScrollPane();
this.lista = new ArrayList<>();
this.scroll.setAccessibleRole(javafx.scene.AccessibleRole.PARENT);
this.scroll.setHbarPolicy(javafx.scene.control.ScrollPane.ScrollBarPolicy.NEVER);
this.scroll.setLayoutX(0);
this.scroll.setLayoutY(0);
this.scroll.setPrefHeight(735);
this.scroll.setPrefWidth(519);
this.scroll.setVvalue(1.0);
this.scroll.setFitToHeight(true);
this.scroll.setFitToWidth(true);
this.scene = new Scene(this.scroll);
this.scene.getStylesheets().add(getClass().getResource("/br/com/teste/commerce/chat/css/style.css").toString());
this.chatBox.heightProperty().addListener(observable -> scroll.setVvalue(1D));
thread = new Thread(new Runnable() {
@Override
public void run() {
//
}
});
}
public void addMessage(String mensagem, String origem, boolean mostrandoAtalhos) {
mensagem = mensagem.replace("u000A", "\n");
Text text=new Text(mensagem);
text.setFill(Color.BLACK);
text.getStyleClass().add("message");
TextFlow tempFlow=new TextFlow();
if(origem.equals("0")){
Text txtName=new Text();
txtName.getStyleClass().add("txtName");
tempFlow.getChildren().add(txtName);
}
if (mostrandoAtalhos) {
text.setWrappingWidth(20);
tempFlow.setMaxWidth(300);
} else {
text.setWrappingWidth(80);
tempFlow.setMaxWidth(650);
}
tempFlow.getChildren().add(text);
TextFlow flow=new TextFlow(tempFlow);
HBox hbox=new HBox(20);
Circle img =new Circle(32,32,16);
img.getStyleClass().add("imageView");
if (origem.equals("0")) {
tempFlow.getStyleClass().add("tempFlowFlipped");
flow.getStyleClass().add("textFlowFlipped");
chatBox.setAlignment(Pos.TOP_LEFT);
hbox.setAlignment(Pos.CENTER_LEFT);
hbox.getChildren().add(img);
hbox.getChildren().add(flow);
}else{
text.setFill(Color.BLACK);
tempFlow.getStyleClass().add("tempFlow");
flow.getStyleClass().add("textFlow");
hbox.setAlignment(Pos.BOTTOM_RIGHT);
hbox.getChildren().add(flow);
hbox.getChildren().add(img);
//}
}
hbox.getStyleClass().add("hbox");
Platform.setImplicitExit(false);
Platform.runLater(() -> {
chatBox.getChildren().addAll(hbox);
});
}