使矩形透明 [英] Make Rectangle transparent
本文介绍了使矩形透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使绘制的矩形鼠标透明,以查看桌面. 以下代码绘制了我的矩形.我该添加些什么? 感谢您的帮助
I need to make a drawn rectangle mouse transparent, in order to see the desktop. The following code draws my rectangle. What should I add to get that ? Thanks for help
public void start(Stage primaryStage) {
Group group = new Group();
Rectangle rect = new Rectangle(20,20,200,200);
rect.setArcHeight(15);
rect.setArcWidth(15);
rect.setStroke(Color.BLACK);
group.getChildren().add(rect);
Scene scene = new Scene(group, 300, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
推荐答案
由于JavaFX中的屏幕图是分层结构,要显示桌面,还需要使Stage
和Scene
透明,并使用形状算术":
Since the screen graph in JavaFX is in a hierarchical structure, to show desktop you need to also make the Stage
and Scene
transparent, and use shape "arithmetic":
@Override
public void start(Stage stage) {
Group group = new Group();
Rectangle rect = new Rectangle(0, 0, 350, 300);
Rectangle clip = new Rectangle(20, 20, 200, 200);
clip.setArcHeight(15);
clip.setArcWidth(15);
Shape shape = Shape.subtract(rect, clip);
shape.setFill(Color.GRAY);
group.getChildren().add(shape);
Scene scene = new Scene(group);
scene.setFill(Color.TRANSPARENT);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
稍后,您可以将可拖动功能添加到窗格/组.
Later you can add draggable feature to the pane/group.
这篇关于使矩形透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文