龙空技术网

Javafx布局之Anchorpane

人人都是AI创作师 62

前言:

如今姐妹们对“imageview图片不显示javafx”可能比较关注,朋友们都想要分析一些“imageview图片不显示javafx”的相关内容。那么小编在网上汇集了一些对于“imageview图片不显示javafx””的相关内容,希望朋友们能喜欢,你们快快来学习一下吧!

Anchorpane锚点窗格允许子节点的边缘锚定到锚点窗格边缘的偏移量。如果锚窗格具有边框和/或填充集,则将从这些插图的内边缘测量偏移

package com.example.demo;import javafx.application.Application;import javafx.collections.ObservableList;import javafx.scene.Scene;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.layout.AnchorPane;import javafx.stage.Stage;public class AnchorPaneExample extends Application {   @Override    public void start(Stage stage) {      //读取一张图片      Image image = new Image(getClass().getResource("/images/a.gif").toExternalForm());      ImageView imageView = new ImageView(image);      imageView.setFitWidth(200);      imageView.setFitHeight(200);      //创建AnchorPane      AnchorPane anchorPane = new AnchorPane();               //设置锚点,TopAnchor 顶部到图片的距离      AnchorPane.setTopAnchor(imageView, 200.0);  //设置200突出显示      AnchorPane.setLeftAnchor(imageView, 50.0);      AnchorPane.setRightAnchor(imageView, 50.0);      AnchorPane.setBottomAnchor(imageView, 50.0);             //Retrieving the observable list of the Anchor Pane       ObservableList list = anchorPane.getChildren();              //Adding imageView to the pane      list.addAll(imageView);               //创建scene对象      Scene scene = new Scene(anchorPane);              //设置标题      stage.setTitle("AnchorPane例子");               //Adding scene to the stage       stage.setScene(scene);                 //显示内容      stage.show();    }    public static void main(String args[]){       launch(args);    } }

运行后效果如图:

视频加载中...

标签: #imageview图片不显示javafx #javafx pane布局