代码之家  ›  专栏  ›  技术社区  ›  TychoTheTaco

JavaFX嵌套网格窗格对齐

  •  0
  • TychoTheTaco  · 技术社区  · 5 年前

    我试过使用GridPane.halignment=“RIGHT”,但这对标签没有影响。

    enter image description here

    enter image description here

    我的布局代码如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.canvas.Canvas?>
    <?import javafx.scene.control.Label?>
    
    <GridPane xmlns="http://javafx.com/javafx"
              xmlns:fx="http://javafx.com/fxml"
              fx:controller="com.bbf.layout.MainLayout">
    
        <GridPane fx:id="stats" GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.halignment="RIGHT" style="-fx-background-color: red;">
            <Label fx:id="frame_count_label" text="Frame: 123" GridPane.columnIndex="0" GridPane.rowIndex="0" style="-fx-background-color: blue;"/>
            <Label fx:id="processing_time_label" text="Processed in 45 ms." GridPane.columnIndex="1" GridPane.rowIndex="0" GridPane.halignment="RIGHT" style="-fx-background-color: green;"/>
        </GridPane>
    
        <Canvas fx:id="video_canvas" GridPane.columnIndex="0" GridPane.rowIndex="1" width="640" height="480"/>
    
        <GridPane fx:id="kb_shortcuts" GridPane.columnIndex="0" GridPane.rowIndex="2">
            <Label text="[E] Toggle Overlay" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
            <Label text="[S] Previous Frame" GridPane.columnIndex="1" GridPane.rowIndex="0" />
            <Label text="[D] Next Frame" GridPane.columnIndex="2" GridPane.rowIndex="0" />
        </GridPane>
    
    </GridPane>
    

    如何按所需方式对齐这些标签?GridPane对我想做的事情来说是不是很理想?我对JavaFX相当缺乏经验,但对Android的布局管理器很熟悉。

    0 回复  |  直到 5 年前
        1
  •  0
  •   TychoTheTaco    5 年前

    嵌套列中的第二列 GridPane 不足以使对齐产生任何影响。简单地添加 GridPane.hgrow="ALWAYS"