Java语言程序设计【4】
2021/10/26 12:09:47
本文主要是介绍Java语言程序设计【4】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
第十四章
- FlowPane
- GridPane
FlowPane
FlowPane将结点按照加入的次序,水平方向从左到右水平或者垂直方向从上到下地放置。
package Chap14; import Chap12.Test; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; public class ShowFlowPane extends Application { @Override public void start(Stage primaryStage) throws Exception { FlowPane pane = new FlowPane(); //创建一个Insets并给出边框大小(顶、右、底、左) pane.setPadding(new Insets(11,12,13,14)); //水平间距 pane.setHgap(5); //垂直间距 pane.setVgap(5); //Place nodes in the pane pane.getChildren().addAll(new Label("First Name:"),new TextField(),new Label("MI:")); //显式引用,因为要来设置属性 TextField tfmi = new TextField(); //将MI文本域的首选列数设置为1 tfmi.setPrefColumnCount(1); pane.getChildren().addAll(tfmi,new Label("Last Name:"),new TextField()); //Creat a scene and place it in the stage Scene scene = new Scene(pane,200,250); primaryStage.setTitle("ShowFlowPane"); primaryStage.setScene(scene); primaryStage.show(); } }
运行结果:
GridPane
GridPane将结点安排在一个网格(矩阵)结构中。结点放在一个指定下标的列和行中。
package Chap14; import javafx.application.Application; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class ShowGridPane extends Application { @Override public void start(Stage primaryStage) throws Exception { GridPane pane = new GridPane(); //对齐方式设为居中 pane.setAlignment(Pos.CENTER); pane.setPadding(new Insets(11.5,12.5,13.5,14.5)); pane.setHgap(5.5); pane.setVgap(5.5); //将标签置于0行0列 pane.add(new Label("First Name:"),0,0); pane.add(new TextField(),1,0); pane.add(new Label("MI:"),0,1); pane.add(new TextField(),1,1); pane.add(new Label("Last Name:"),0,2); pane.add(new TextField(),1,2); Button btAdd = new Button("Add Name"); pane.add(btAdd,1,3); //将按钮在单元格中右对齐 GridPane.setHalignment(btAdd, HPos.RIGHT); //创建场景并放在舞台 Scene scene = new Scene(pane); primaryStage.setTitle("ShowGridPane"); primaryStage.setScene(scene); primaryStage.show();//Display the stage } }
运行结果:
这篇关于Java语言程序设计【4】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?