javaFX-如何在屏幕底部放置文本区域

标签 java javafx jfoenix

我是 javafx 的初学者,所以我正在开发聊天应用程序 UI。 我想在屏幕底部放置一个文本区域,并且无论屏幕大小如何都必须保持在这个位置。

这是我的 FXML 文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXTextArea?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>

<GridPane fx:id="gridParent" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="550.0" prefWidth="750.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bmi.client.AccueilController">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" maxWidth="228.0" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
   <children>
      <AnchorPane fx:id="listePane" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #1D232A;" />
      <AnchorPane fx:id="convPane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
         <children>
            <Pane fx:id="namePane" prefHeight="47.0" prefWidth="375.0" style="-fx-background-color: #b0b0b0;">
               <children>
                  <Label fx:id="nameLabel" layoutX="14.0" layoutY="15.0" />
               </children>
            </Pane>
            <JFXTextArea fx:id="messageArea" layoutY="482.0" prefHeight="68.0" prefWidth="375.0" promptText="Ecrire un message..." style="-fx-background-color: white; -fx-border-radius: 10px;"  />
         </children>
      </AnchorPane>
   </children>
</GridPane>

这是 FXML 文件的屏幕截图 image

当我调整屏幕大小时,我得到类似的东西: image2

最佳答案

这是使用 HBox 作为根的一种方法。

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXTextArea?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>

<HBox prefHeight="550.0" prefWidth="750.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane fx:id="listePane" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #1D232A;" />
      <VBox prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
         <children>
            <Pane fx:id="namePane" prefHeight="47.0" prefWidth="375.0" style="-fx-background-color: #b0b0b0;" VBox.vgrow="ALWAYS">
               <children>
                  <Label fx:id="nameLabel" layoutX="14.0" layoutY="15.0" />
               </children>
            </Pane>
            <JFXTextArea fx:id="messageArea" prefHeight="68.0" prefWidth="375.0" promptText="Ecrire un message..." style="-fx-background-color: white; -fx-border-radius: 10px;" />
         </children>
      </VBox>
   </children>
</HBox>

关于javaFX-如何在屏幕底部放置文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47721175/

相关文章:

Java - 将带有列表变量的对象转换为对象列表

java - 如何使用 Spring Security 将经过身份验证的用户的 IP 地址保存到数据库?

JAVAFX,倒计时不起作用

java - 尝试在 NetBeans 上使用 JavaFX 创建 Maven 项目?

java - 更改大小 DatePicker JavaFX - 图书管理员 JFoenix

java - 按日期升序排序,最后为空

java - Spring-Boot:并发处理多个请求

Java FX 无法加载 Font Awesome 图标

css - 如何在 JFoenix 日期选择器中编辑日期单元格和年份单元格