如何限制物品的可见性?

编程入门 行业动态 更新时间:2024-10-24 12:20:44
本文介绍了如何限制物品的可见性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我们有一个AnchorPane,它有一个子级Pane,例如,我们有一个Button. 我希望仅在此Pane内部显示此Button. 换句话说,如果Pane不在Pane内,则应将其切掉.现在,即使Button不在Pane矩形内,也可以看到.

Imagine that we have an AnchorPane, it has child Pane and there we have Button, for example. I want this Button to be shown only inside this Pane. In other words, it whould be cut by the Pane edges if it is not completely within Pane. Now the Button can be visible even if it is out of Pane rectangle.

推荐答案

这是剪辑.

示例:

import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class ClipTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { Group root = new Group(); StackPane pane = new StackPane(); pane.setMaxWidth(100); pane.setMaxHeight(100); pane.setLayoutX(50); pane.setLayoutY(50); Rectangle rect = new Rectangle(100, 100); rect.setFill(null); rect.setStroke(Color.RED); Rectangle rect2 = new Rectangle(150, 150); rect2.setFill(Color.BLUE); pane.getChildren().addAll(rect2, rect); root.getChildren().add(pane); // Rectangle clip = new Rectangle(100, 100); // clip.setLayoutX(25); // clip.setLayoutY(25); // pane.setClip(clip); Scene scene = new Scene(root, 250, 250); primaryStage.setScene(scene); primaryStage.show(); } }

这将产生:

取消注释有关剪辑的行会产生:

Uncommenting the lines regarding the clip produces:

更多推荐

如何限制物品的可见性?

本文发布于:2023-11-30 01:16:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:物品   见性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!