我正在建立聊天,并且我需要我的消息背景(“锚定”窗格)来调整流消息的大小,否则this is what happens
这是我的代码:
Message.fxml
<VBox xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.MessageController">
<children>
<AnchorPane maxWidth="600.0" minHeight="52.0" minWidth="150.0" styleClass="message-background">
<children>
<Text fx:id="usernameField" strokeType="OUTSIDE" strokeWidth="0.0" text="username" AnchorPane.leftAnchor="15.0" AnchorPane.topAnchor="8.0" />
<TextFlow fx:id="messageField" minHeight="20.0" minWidth="130.0" AnchorPane.bottomAnchor="8.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="24.0" />
</children>
</AnchorPane>
</children>
</VBox>
MainScreen.fxml Message.fxml的VBox在MainScreen.fxml中应该是“ chatPaneContent”
<AnchorPane id="MainPane" prefHeight="640.0" prefWidth="1000.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="205.0" AnchorPane.rightAnchor="75.0" AnchorPane.topAnchor="78.0">
<effect>
<DropShadow blurType="GAUSSIAN" color="#000000ad" offsetX="-6.0" offsetY="6.0" />
</effect>
<children>
<JFXTextField fx:id="inputField" layoutX="30.0" layoutY="590.0" onKeyPressed="#sendFromReturn" prefHeight="25.0" prefWidth="814.0" promptText="Messaggio" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="140.0" />
<JFXButton fx:id="sendButton" layoutX="860.0" layoutY="564.0" onAction="#sendMessage" prefHeight="49.0" prefWidth="96.0" text="Invia" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<ScrollPane fx:id="chatPane" layoutX="14.0" layoutY="13.0" prefHeight="550.0" prefWidth="975.0" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="13.0">
<content>
<VBox fx:id="chatPaneContent" />
</content></ScrollPane>
</children>
</AnchorPane>
MainController.java
Message message = new Message();
message.setUsername(SocketInfo.getUsername());
message.setMessage(inputField.getText());
outbound.sendMessage(inputField.getText());
chatPaneContent.getChildren().add(message);
inputField.clear();
该如何解决?我想念什么吗?