简体   繁体   English

锚窗格未使用流文本调整大小

[英]Anchor pane not resizing with flowtext

I'm building a chat, and I need my message background (Anchor pane) to resize with the flow message, otherwise this is what happens 我正在建立聊天,我需要我的消息背景(锚定窗格)来调整流消息的大小,否则会发生这种情况

This is my code: 这是我的代码:

Message.fxml 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 The VBox of Message.fxml is supposed to be "chatPaneContent" in MainScreen.fxml MainScreen.fxml MessageScreen.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 MainController.java

Message message = new Message();
message.setUsername(SocketInfo.getUsername());
message.setMessage(inputField.getText());

outbound.sendMessage(inputField.getText());
chatPaneContent.getChildren().add(message);

inputField.clear();

What can I do to solve this? 我该怎么解决? Am I missing anything? 我有什么想念的吗?

也许以百分比设置组件的大小可能有助于了解这一点 ,但是侦听表单调整大小可能也很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM