我试过使用GridPane.halignment=“RIGHT”,但这对标签没有影响。
我的布局代码如下所示:
<?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的布局管理器很熟悉。