前言:
目前咱们对“javafx pane布局”大体比较关心,大家都需要学习一些“javafx pane布局”的相关知识。那么小编在网上网罗了一些有关“javafx pane布局””的相关内容,希望小伙伴们能喜欢,咱们快快来了解一下吧!BorderPane将整个面板划分五个区域,分别是上、下、左、右、中,每个区域可以放置一个控件。然后控件里也可以嵌套控件.
下面是代码示例:
package com.example.demo;import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.Label;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.layout.BorderPane;import javafx.scene.paint.Color;import javafx.scene.text.Text;import javafx.stage.Stage; public class BorderPaneExample extends Application { @Override public void start(Stage stage) { Text topText = new Text(); topText.setText("hi 我是top "); //字体设置为紫色 topText.setFill(Color.BLUEVIOLET); Label bottomLabel = new Label(); bottomLabel.setText("hi 我是bottom "); //css bottomLabel.setStyle("-fx-text-fill: pink;-fx-border-color: pink;-fx-border-width: 2;-fx-border-style: solid"); //读取一张图片 Image image = new Image(getClass().getResource("/images/a.gif").toExternalForm()); ImageView imageViewLeft = new ImageView(image); imageViewLeft.setFitWidth(200); imageViewLeft.setFitHeight(200); ImageView imageViewCenter = new ImageView(image); imageViewCenter.setScaleX(2); //放大倍數 imageViewCenter.setScaleY(2); imageViewCenter.setFitWidth(200); imageViewCenter.setFitHeight(200); ImageView imageViewRight = new ImageView(image); imageViewRight.setFitWidth(200); imageViewRight.setFitHeight(200); BorderPane borderPane = new BorderPane(); borderPane.setMinWidth(900); borderPane.setTop(topText); borderPane.setBottom(bottomLabel); borderPane.setLeft(imageViewLeft); borderPane.setRight(imageViewRight); borderPane.setCenter(imageViewCenter); Scene scene = new Scene(borderPane); stage.setTitle("BorderPane例子"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
运行代码后显示:
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #javafx pane布局