【问题标题】:javaFX- how to place a textarea in the bottom of the screenjavaFX-如何在屏幕底部放置一个textarea
【发布时间】:2017-12-08 19:44:47
【问题描述】:

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

【问题讨论】:

  • 使用BorderPane
  • 如果您使用 BorderPane,您可以将内容固定在屏幕的顶部、右侧、底部或左侧,内容也位于中间。我建议这样做,而不是在其中使用带有 AnchorPanes 的 GridPane。这样,当您调整大小时,它们会适当地移动。
  • 我想如果我使用 BorderPane 我不能使用面板作为侧边栏,并且 TextArea 将覆盖整个宽度?

标签: java javafx jfoenix


【解决方案1】:

这是使用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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    相关资源
    最近更新 更多