【发布时间】:2026-02-07 13:50:01
【问题描述】:
【问题讨论】:
标签: javafx fxml scenebuilder
【问题讨论】:
标签: javafx fxml scenebuilder
我不使用场景构建器,我更喜欢自己创建 FXML 文件,尤其是因为它没有响应性。
定义应用程序 UI 的目的是选择好的布局。根据您想要实现的目标,有些比其他响应更快。
我看到了您的第一篇文章,但我没有使用 JFoenix,那么这里有一个 非常 轻量级/简单示例,其中包含“常规”组件,可以帮助您使您的应用程序具有响应性。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="GridPane" >
<children>
<VBox GridPane.rowIndex="0" GridPane.columnIndex="0" style="-fx-background-color:grey; -fx-opacity:0.7;"/>
<VBox GridPane.rowIndex="0" GridPane.columnIndex="2" style="-fx-background-color:grey; -fx-opacity:0.7;"/>
<VBox GridPane.rowIndex="0" GridPane.columnIndex="4" style="-fx-background-color:grey; -fx-opacity:0.7;"/>
<HBox GridPane.rowIndex="1" GridPane.columnIndex="2" alignment="CENTER" spacing="10.0">
<Button text="ADD" style="-fx-background-color:DODGERBLUE;-fx-border-radius:10;-fx-background-radius:10"/>
<Button text="UPDATE" style="-fx-background-color:DODGERBLUE;-fx-border-radius:10;-fx-background-radius:10"/>
<Button text="CLEAN" style="-fx-background-color:DODGERBLUE;-fx-border-radius:10;-fx-background-radius:10"/>
</HBox>
</children>
<columnConstraints>
<ColumnConstraints percentWidth="30.0" />
<!-- Space -->
<ColumnConstraints percentWidth="5.0" />
<ColumnConstraints percentWidth="30.0" />
<!-- Space -->
<ColumnConstraints percentWidth="5.0" />
<ColumnConstraints percentWidth="30.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints percentHeight="80.0" />
<RowConstraints percentHeight="20.0" />
</rowConstraints>
<padding>
<Insets top="10.0" left="10.0" bottom="10.0" right="10.0"/>
</padding>
</fx:root>
【讨论】:
HBox 也可能在这里工作。 (或者,我猜是BorderPane 和HBox,中间有三个VBox,底部有HBox 中的三个按钮。)