簡體   English   中英

錨窗格未使用流文本調整大小

[英]Anchor pane not resizing with flowtext

我正在建立聊天,我需要我的消息背景(錨定窗格)來調整流消息的大小,否則會發生這種情況

這是我的代碼:

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 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

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

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

inputField.clear();

我該怎么解決? 我有什么想念的嗎?

也許以百分比設置組件的大小可能有助於了解這一點 ,但是偵聽表單調整大小可能也很有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM