如何使用JavaFX创建HBox?
盒子
在这种布局中,节点排列在单个水平行中。您可以通过实例化javafx.scene.layout.HBox类在应用程序中创建hbox。您可以使用setPadding()方法在hbox周围设置填充。
要将节点添加到此窗格中,可以将它们作为构造函数的参数传递,也可以将它们添加到窗格的可观察列表中,如下所示:
getChildren().addAll();
示例
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class HBoxExample extends Application {
public void start(Stage stage) {
//创建标签
Label label1 = new Label("用户名: ");
Label label2 = new Label("Password: ");
//创建文本和密码字段
TextField textField = new TextField();
PasswordField pwdField = new PasswordField();
//为节点添加标签
HBox box = new HBox(5);
box.setPadding(new Insets(50, 5 , 5, 50));
box.getChildren().addAll(label1, textField, label2, pwdField);
//设置舞台
Scene scene = new Scene(box, 595, 150, Color.BEIGE);
stage.setTitle("HBox示例");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便