1
I have a problem, where, when trying to readjust the screen, the text that is inside a TextFlow
, goes off the screen, and it’s 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);
});
}
I’m doing a simple chat. This part is just where he adds the messages in the dashboard. I updated the code for you to see better too
– William
Another observation is that this screen is an implementation of a Javafx screen within a Swing application
– William
The compatibility between the two is not good ... maybe because it is a simple screen is more pertinent to do in Swing even.
– Gustavo Fragoso
The problem is that many things I need to do don’t look very cool in Swing. Like this visual part of the chat. It’s not just a simple chat. I am using this code as a basis: https://github.com/Oshan96/ChatRoomFX
– William